Introduction of Entity Framework learning 2--objectcontext, ObjectQuery, ObjectStateEntry and Objectstatemanager classes
This section briefly introduces the more important classes of ObjectContext, ObjectQuery, ObjectStateEntry, and Objectstatemanager in the EF. They are all located under the System.Data.Objects namespace under System.Data.Entity.dll. In subsequent chapters, we often use some of their methods in order to complete some of our operations or purposes. In this section, we simply explain the various classes of methods that we may use later to facilitate our subsequent learning.
ObjectContext encapsulates the connection between the. NET Framework and the database. This class is used as a gateway for Create, read, update, and delete operations.
The ObjectContext class is used as the primary class for interacting with data as objects that are instances of entity types defined in the EDM.
An instance of the ObjectContext class encapsulates the following:
L A connection to the database, encapsulated in the form of a EntityConnection object.
L describes the metadata of the model, encapsulated in the form of a MetadataWorkspace object.
L The Objectstatemanager object that is used to manage persisted objects in the cache.
ObjectContext the member methods of the class to illustrate the following:
L AcceptAllChanges ()
Accept all changes to the entity object
L AddObject (String,object)
To add an entity object to the established entity container
L Applypropertychanges (String,object)
The corresponding original object in the container will be applied as a change to the assigned entity object property.
L Attach (System.Data.Objects.DataClasses.IEntityWithKey entity)
Attach an entity object with a primary key to the default container
L Attach (String,object)
To attach an entity object to a specified entity container
L Createentitykey (String,object)
Creates an entity primary key for the specified entity object or, if an entity primary key already exists, returns the primary key of the entity directly
L createquery<t> (string,params objectparameter[])
Creates a ObjectQuery object from the given query string.
L DeleteObject (object)