What distinguishes these two, and which is preferred? using modify object state
context.Entry(employeeFromDB).State = EnitityState.Modified;
You are essentially calling a function on the underlying
Rather than getting and altering a Property directly through the DbContext, you should use your DbContext class.
The first illustration
can only be employed to change an
of an entity that is already present in the situation. An exception is thrown if you attempt to edit something that doesn't exist.
Verify the Exceptions in ObjectStateManager.ChangeObjectState.
In the second case, if the object is introduced but doesn't already exist in the context, you will still receive an exception.
however, by simply making a change, the same strategy may be used to add a new record.
You must also use your DbContext to retrieve the underlying ObjectContext