views:

84

answers:

1

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.

+1  A: 

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

Stephen Newman
This was moderately close to what I needed. The ApplyChanges method did not make it into the .NET 4.0 release. I found this example which is what I used to complete the task: http://msdn.microsoft.com/en-us/library/bb896248.aspx
Brandon
Glad you've got a solution - all the best, Steve.
Stephen Newman