Alex Rivera | Logout

Is EntityState.Modified required for an update?

Asked 2012-03-15T10:45:51.473
19

I've seen a lot of people when updating a record use:

...
ms.Status = status;
db.Entry(ms).State = EntityState.Modified;
db.SaveChanges();

Is this line required? I was able to do an update without it.

db.Entry(ms).State = EntityState.Modified;

I was wondering what this statement is actually used for if the context already knows it should update that record without you specifying it explicitly then why bother specifying it explicitly?

Edit
Report

1 Answer

1

From my understanding this only needs to be used if the entity has been re-attached to the context. Otherwise no.

answered 2012-03-15T10:57:46.057

Your Answer