0

I have exposed entity frame work DBContext's POCO entities to WCF (without tracking enabled) and through my client when i am trying to update a combination of Parent and related entieis. Only the parent entity is gets updated but child entity is not updated.

I am trying some thing like … A Customer has one or more Customer Address entities. In my client , I have added a new customer Adress , deleted an existing customer Address, and updated an existing Customer Address and modified some thing in Customer Object iteslf. Now, i want to update these changes at one shot.

Currently, it’s updating only the customer and ignoring the rest.

I was under impression that, with EF 4.1 the change tracking capablity has been improved and we can acheive this with out STE (self tracking entities). My assumption is correct? Can it possible with DBContext?. Any help or directions?

1 Answers1

1

No. EF change tracking tracks changes only for attached entity. If you serialize entity and send it elsewhere it is not tracked anymore. It becomes detached scenario and you are responsible for telling EF what changes happened on your WCF client. If you just attach the entity and set parents state to modified it will do exactly that - it will only update parent because you didn't tell it that anything else has changed.

So either send additional information from client about modified entities and set every entity or relation to correct state prior to saving changes or load your current state (current parent and children) from database and merge it with state received from the client.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670