State management, identity management, and relationship management
Change tracking or tracking the modifications to objects in Entity Framework is handled by a component called ObjectStateManager
. The context delegates change tracking management calls to this component at runtime. The state manager is responsible for adding, deleting, and attaching entities to and from the context. It also holds the in-memory collection of objects, does the necessary identity checks, and keeps track of relationships of entities. Note that ObjectStateManager
is exposed as a property called ObjectStateManager
of ObjectContext
.
Here's how the ObjectStateManager
instance of the SecurityDBEntities
class can be accessed:
using (SecurityDBEntitiesvar ctx = new SecurityDBEntities()) { var objStateManager = ctx.ObjectStateManager; }
In relational databases, relationships, or associations between the database tables are defined through the use of foreign keys. A foreign key is just another column in...