ObjectStateManager 和分离实体状态
我正在使用实体框架,但它的某些功能对我来说仍然不清楚。主要比较难理解的是:
SubmitChanges
流程;- 调用更新-删除-插入方法的顺序;
- 了解
ObjectStateManager
- 分离的
EntityState
及其提交过程的一部分;
提供您的解释或提供一些有用的链接。
I'm using Entity Framework and some parts of its functionality are still unclear for me. The main things that are hard to understand are:
SubmitChanges
process;- Order of invoking update-delete-insert methods;
- Understanding of
ObjectStateManager
- Detached
EntityState
and it's part in submitting process;
Provide your explanations or give some useful links.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ObjectStateManager
是一个公开有关被跟踪实体的信息的组件。 EF 可以持久化的每个实体都必须被跟踪 = 附加。分离的实体对于 EF 来说是未知的(它们不会被跟踪),因此当您调用SaveChanges
时,不会保存它们的更改(EF 中没有SubmitChanges
)。跟踪包括维护有关实体或关系的初始状态以及对它们所做的更改的信息。它还包含实体的全局状态。调用 SaveChanges 时的过程取决于您配置 EF 跟踪更改的方式、获取实体的方式以及您所做的更改。
更改跟踪是一项功能,允许 EF 跟踪附加到上下文的实体上应用的更改(默认情况下附加查询加载的每个实体)。 EF 包含更改跟踪的版本:
SaveChanges
时,状态已设置。数据修改操作的顺序是EF内部实现的。基本顺序由描述实体之间依赖关系的映射定义。
ObjectStateManager
is a component exposing information about tracked entities. Each entity which can be persisted by EF must be tracked = attached. Detached entities are unknown to EF (they are not tracked) and so their changes are not saved when you callSaveChanges
(there is noSubmitChanges
in EF). Tracking consists of maintaining information about initial state of the entity or relation and changes done to them. It also contains the global state of the entity.The process when you call SaveChanges depends on the way how you configured EF to track changes, on the way how you got the entity and on the changes you did.
Change tracking is a feature which allows EF to track changes applied on entities attached to the context (each entity loaded by the query is by default attached). EF contains to version of change tracking:
SaveChanges
it compares stored state of the entity (obtained when the entity was loaded) and the current data in the entity and set its state accordingly.SaveChanges
are states are already set up.The order of data modification operations is EF internal implementation. The basic order is defined by your mapping where dependency between entities is described.