This project has moved. For the latest updates, please go here.
1
Vote

Issues with disconnected data context

description

Hi,

I design web application using N-Tier Entity Framework. To save resources I have to use disconnected data contexts on client side: each time I need to read/write data I create new data context and destroy it immediately after read/write block has been done.

For example,
  • user opens entity for edition: new data context created, entity loaded in object A, data context destroyed;
  • user takes his/her time to edit data stored locally in client application in object A;
  • user saves changes: new data context created, object A does not exist in new data context so the same entity gets loaded in object B, data from object A gets copied into object B, object B gets saved, data context destroyed.
I have two issues so far with step "data from object A gets copied into object B". I use dataContext.AttachAsModified(A, B). I assume it was created to serve such purposes. Here are the issues:

Issue#1. I have mentioned that in Discussion: concurrency properties not managed inside AttachAsModified(). To have EF build-in concurrency functionality work each B.ChangeTracker.OriginalValues["<concurrency property>"] has to get assigned value from A.<concurrency property>.

Issue#2. AttachAsModified(A, B) does not copy navigation properties from A to B. In case of Master-Detail entity (like, Order-Order_Details) only changes in master part get saved as result. B.Refresh(A) called from AttachAsModified(A, B) should not ignore details list and entire object tree has to be discovered for changes.

Right now in my prototype project I have to address above issues outside of AttachAsModified() but it would be nice get it addressed in the framework.

Please let me know if you need more clarification, code samples, etc.

Thank you,

Serge

comments

ChristofSenn wrote Dec 27, 2016 at 5:51 PM

AttachAsModified was created to support WCF RIA services which comes with its own limitations and is actually absolete. Try use Attach instead, to have navigation properties handled.