0

I have a situation where I'm saving data from a WPF client application by calling a Web API method. The flow is that the WPF client calls a Get Web API method, manipulates a bunch of the data on the client, and then calls a Post Web API method to save the data. It's a single unit of work, and it's a pretty complex object model with several child objects.

I thought that simply calling the Attach method on the data context would take care of syncing all of the changes, but that doesn't appear to be the case. My question is, how do I save all of this data without writing some sort of horrendous synchronization logic? It seems like EF should be able to handle this scenario.

Frank Hoffman
  • 887
  • 1
  • 11
  • 16
  • You should manipulate all the data in one place before you commit it to the database. So if you have a method that changes a load of properties, then you send that data to EF, via the attach, you must commit once you are done. Plus EF only saves the state of objects within one context call I believe. So in a single `using (var context = new IDbContextFactory.Create())` after that has exited the context is destroy, or at least the data it knows – Callum Linington Aug 30 '14 at 20:57
  • possible duplicate of [Entity Framework 6 Update Graph](http://stackoverflow.com/questions/23999798/entity-framework-6-update-graph) – Gert Arnold Aug 30 '14 at 22:44
  • Yeah I think you maybe right about the duplicate post. I tried out GraphDiff but I think it has trouble dealing with self-referenced tables. At least, it seemed to be that way in my situation. Hopefully EF7 will just be able to deal with it. I think NHibernate has a provision for this. – Frank Hoffman Sep 01 '14 at 04:21

0 Answers0