Entity Framework Db.SaveChanges() not working?
14,059
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.
Comments
-
PsyGnosis almost 2 years
Can u tell me what is the problem?
-
Liviu Mandras almost 10 yearswhat do you mean "is not working"? what is the exception? what EF version are you using? how do you pass the
db
variable to theCustomer
entity and to the click handler in the aspx page? -
phil soady almost 10 yearscan you tell us what the error is ? My Crystal ball is in for service
-
PsyGnosis almost 10 yearsI am not getting an error. it's not save the values
-
PsyGnosis almost 10 yearsdb variable in the same class like entity db = new entity(); and also aspx page has different db variable. I think its not working because of that
-