I am experiencing the pain in the A** of EF and according too google, I am not the only one with this issue. I Have a list of object that I got from EF and then I set this list as the DataContext (WPF) of an itemscontrol. Since, after the "using" block the context is destroyed, I would have to make a new query and object with the same ID When wishing to save the changes. I try to attach it to the Context, I try saving the changes, but they are not stored.
Some people have tried several things, but does maybe someone know of a handy and smart solution for this problem?
I tried Attach()
, AttachTo()
, nothing worked
P.S. It's EF 4.0
EDITED - SOLVED
Adding the following line of code between attaching and saving solved everything in EF 4.0
_context.ObjectStateManager.ChangeObjectState(modifiedEntity, System.Data.EntityState.Modified);
in EF 4.1
_context.Entry(modifiedEntity).State = System.Data.EntityState.Modified;