简体   繁体   English

附加到上下文并保持实体为对象状态

[英]Attaching to context and keeping the entities objectstate

I'm working with Self tracking entities. 我正在与自我跟踪实体合作。 and when i Attach an entity to the context, all the entities related to it and the entity itself gets added in an added state in the context objectstatemanager. 当我将实体附加到上下文时,与它相关的所有实体以及该实体本身都会在上下文objectstatemanager中以添加状态添加。 where as in the entity itself they have a different status, for example unchanged. 与实体本身一样,它们具有不同的状态,例如不变。

How can i attach an entity to the context whilst keeping the right state? 如何在保持正确状态的同时将实体附加到上下文? (the objectstate in the entity) (实体中的对象状态)

i've tried detect changes but it does nothing. 我已经尝试检测更改,但是它什么也没做。 i hoped that detect changes would synchronize the object state of the context to the object state of the entity. 我希望检测到的更改将使上下文的对象状态与实体的对象状态同步。

If you are using self tracking entities you should not use Attach , AddObject or DetectChanges directly. 如果您使用的是自我跟踪实体,则不应直接使用AttachAddObjectDetectChanges You should instead use ApplyChanges extension method defined on ObjectSet . 您应该改为使用ObjectSet定义的ApplyChanges扩展方法。 This method will internally attach entities to the context and set current state based on the state stored in self tracking entities. 此方法将内部将实体附加到上下文,并根据存储在自我跟踪实体中的状态设置当前状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM