简体   繁体   中英

Updating a Detached Entity Instance using Entity Framework 4.0

I am utilizing Entity Framework 4.0 and WCF. I am new to using Entity Framework and am more familiar with 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).

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? This is designed to make handling updates of detached entities much easier. http://msdn.microsoft.com/en-us/library/ee789839.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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