简体   繁体   English

使用Entity Framework 4.0更新分离的实体实例

[英]Updating a Detached Entity Instance using Entity Framework 4.0

I am utilizing Entity Framework 4.0 and WCF. 我正在使用Entity Framework 4.0和WCF。 I am new to using Entity Framework and am more familiar with NHibernate. 我是使用Entity Framework的新手,对NHibernate更熟悉。 However, I am concerned about detached instances of objects when performing an update. 但是,我担心执行更新时对象的分离实例。

I have looked on various websites where they retrieve an object, attach the instance to their context, and set all properties to be modified but this leaves two problems: 我查看了各种网站,他们检索对象,将实例附加到其上下文,并设置要修改的所有属性,但这留下了两个问题:

  1. All fields are updated in the database (not a huge problem, but adds overhead for each update statement). 所有字段都在数据库中更新(这不是一个大问题,但会增加每个更新语句的开销)。
  2. Many of the examples do not handle situations where you may have an IEnumerable property with objects that also need to be updated (this will be a requirement). 许多示例不处理您可能具有IEnumerable属性的情况,其中对象也需要更新(这将是一项要求)。

Is there a 'best practice' example of how to handle updating detached entity instances? 是否存在如何处理更新分离实体实例的“最佳实践”示例? Any guidance is greatly appreciated. 非常感谢任何指导。

Brandon, are you able to make use of the self-tracking entities template? Brandon,您能够使用自我跟踪实体模板吗? This is designed to make handling updates of detached entities much easier. 这旨在使分离实体的处理更新变得更加容易。 http://msdn.microsoft.com/en-us/library/ee789839.aspx http://msdn.microsoft.com/en-us/library/ee789839.aspx

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

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