Entity Framework Overview

Source: Internet
Author: User
Tags list of attributes
Entity Framework Overview

ADO. NET Entity Framework is a solution developed by Microsoft Based on ADO and net.

I. background

It is developed with the development of object-oriented software development methods. Object and relational data are two forms of business entities. Business entities are represented as objects in the memory and relational data in the database. Objects in the memory have associations and inheritance relationships. In the database, relational data cannot directly express many-to-many associations and inheritance relationships. Therefore, Orm generally exists in the form of middleware, mainly to map program objects to relational databases. Hibernate or Nhibernate is a product of this technology, but Microsoft does not have such an object-related tool. to have such a tool, Microsoft developed ADO. NET Entity Framework.

Ii. Development History

Microsoft in. net framework2.0 development period, put forward the concept of objectspace, its technology is similar to nhib.pdf, but objectspace because of the large project so in. net Framework 2.0 is complete when objectspace is not completed, So Microsoft will include it in the next version.. NET Framework, and the design tool (desinger) is added to form the current ADO. NET Entity Framework.

Iii. application scenarios

Use ADO. NET Entity Framework to automatically generate Dal code for us. Ado. NET Entity framework can be used to save, add, delete, modify, and read objects. ADO. NET Entity Framework is responsible for generating SQL statements. We only need to pay attention to objects, rather than paying attention to database structures.

Iv. Architecture

V. main modules and Classes

The Entity Framework is a set of technologies in ADO. Net that support developing data-oriented software applications. The Entity Data Model (EDM) in EF is defined by the following three models and ing files with corresponding file extensions. Conceptual Architecture Definition Language file (. CSDL)-define a conceptual model. Storage Architecture Definition Language file (. SSDL)-defines the storage model (also known as the logical model ). Ing specification language file (. MSL)-defines the ing between the storage model and the conceptual model.

Important classes:

1. objectcontext: objectcontext encapsulates the connection between. NET Framework and the database. This type is used as the gateway for "CREATE", "read", "Update", and "delete" operations.

2. objectquery: There is a useful method totracestring (). This method is used to track the executed SQL statements. Through this method, we can obtain the executed SQL statements, so that we can view and analyze the specific executed SQL statements.

3. objectstateentry: objectstateentry maintains the status (added, deleted, separated, modified, or not changed), key value, and original value of the entity or relational instance. Manage the list of attributes that have been modified

4. objectstatemanager: objectstatemanager is used to maintain object ing, object status/ID management, and the persistence of entity or relational instances.

 

6. Typical crud code: add, delete, query, and modify

1. Obtain the grade list based on the school ID

_ Context. classes. Where (C => C. schoolid = schoolid). Select (C => C. Grade). Distinct (). tolist ()

2. Obtain the class information based on the class ID

Return _ context. classes. firstordefault (C => C. classid = ID)

3. Add a class

_ Context. classes. Add (entity );

Int I = _ context. savechanges ()

4. delete a class

_ Context. Entry <class> (Entity). State =

System. Data. entitystate. Deleted;

Int I = _ context. savechanges ()

5. Modify the class

_ Context. classes. Attach (entity );

_ Context. Entry <class> (Entity). State =

System. Data. entitystate. Modified

Int I = _ context. savechanges ()

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.