I'm using Entity Framework and some parts of its functionality are still unclear for me. The main things that are hard to understand are:
SubmitChanges
process;- Order of invoking update-delete-insert methods;
- Understanding of
ObjectStateManager
- Detached
EntityState
and it's part in submitting process;
Provide your explanations or give some useful links.
ObjectStateManager
is a component exposing information about tracked entities. Each entity which can be persisted by EF must be tracked = attached. Detached entities are unknown to EF (they are not tracked) and so their changes are not saved when you callSaveChanges
(there is noSubmitChanges
in EF). Tracking consists of maintaining information about initial state of the entity or relation and changes done to them. It also contains the global state of the entity.The process when you call SaveChanges depends on the way how you configured EF to track changes, on the way how you got the entity and on the changes you did.
Change tracking is a feature which allows EF to track changes applied on entities attached to the context (each entity loaded by the query is by default attached). EF contains to version of change tracking:
SaveChanges
it compares stored state of the entity (obtained when the entity was loaded) and the current data in the entity and set its state accordingly.SaveChanges
are states are already set up.The order of data modification operations is EF internal implementation. The basic order is defined by your mapping where dependency between entities is described.