当其中一个 EntityManager 更新或保存更改时,哪些数据会看到一组 EntityManager?

发布于 2024-10-09 23:13:43 字数 224 浏览 0 评论 0原文

我对实体框架中的上下文有以下疑问:

假设有三个上下文 d1、d2 和 d3。每个上下文都在应用程序执行流的不同时刻实例化(d3,在 d2 之后,d2,在 d1 之后)。如果应用程序逻辑修改 d2 管理的某些实体并执行 d2.SaveChanges() (或任何暗示更新或创建的操作),则在 d2.SaveChanges() 执行后 d3 和 d1 会看到更改吗?

您能提供一些参考书目来支持您的答案吗?

I'm having the following doubt about contexts in entity framework:

Suppose that there are three contexts d1, d2 and d3. Every context has been instantiated at different moments in the application's execution flux (d3, after d2 and d2, after d1). If application logic modifies some entities managed by d2 and executes d2.SaveChanges() (or any operation implying an update or a create), changes are seen by d3 and d1 after d2.SaveChanges() execution?

Could you provide some bibliography supporting your answer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拔了角的鹿 2024-10-16 23:13:43

仅当您从日期存储中刷新它们后才能看到它们。 d2 中的更改不会影响其他上下文。 d1 和 d3 包含在 d2 中进行更改之前从数据库检索的状态数据。如果您想要最新状态,您必须自己刷新其中的数据。如果这是自动完成的,效率不会很高。这也是为什么上下文的生命周期应该很短的原因。如果你持有它太久,它就会包含过时的实体。

They are seen only after you refresh them from date store. Changes in d2 don't affect other contexts. d1 and d3 contain data in state, that you retrieved from database, before changes made in d2. If you want up to date state, you have to refresh data in them yourself. If this was done automatically, it would be not very efficient. That is also why context's life should be short. If you hold it too long, it contains out of date entities.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文