Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to Entity Framework and I'm using Mock to test my repository. The repository uses a class that implements DbContext.

When I run the update test on an attached entity, it works fine. When I run the same test on a detached entity, it fails because the changes have not been applied. I looked through other forums where they use AttachTo but i cannot find that method with EF6.

I currently use the method Attach to update it. I even tried other methods below but no success. I need advice on that.

myContext.Set<blog>().Attach(detachedBlog);

Entry<blog>(myBlog).State = EntryState.Modified;

Entry<blog>(existingBlog).CurrentValues.SetValues(detachedBlog);
Posted
Comments
Mostafa Asaduzzaman 4-Jun-15 18:32pm    
try the suggestion from: http://stackoverflow.com/questions/20451461/save-detached-entity-in-entity-framework-6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900