Entity Framework Db.SaveChanges() not working?

entity-framework savechanges

Question

Can u tell me what is the problem?

can u tell me what's the problem

1
2
7/9/2014 7:13:53 AM

Accepted Answer

If you are using two different instances of the DbContext (the db variable as you named it) then nothing will be saved when you call SaveChanges on a context different than the one where your entities are tracked. You need to use the Attach method first.

db.customer_images.Attach(item);
db.SaveChanges();

However I think in your case you can avoid the attach step if you refactor a bit you code and don't use the DbContext from the entity itself.

7
7/9/2014 7:58:13 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow