Entity Framework Learning Primary Chapter 2

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.