EF- operating principle

First, what is the EF ?

      Physical infrastructure ( the Entity Framework ) since Microsoft ADO.Net based developed object-relational mapping ( ORM ) solution that solves the problem of persistent objects, the programmer from writing troublesome SQL freed statement.

    advantage:

      It supports multiple databases (Microsoft SQL Server, Oracle and DB2, etc.);

   Powerful mapping engine, can be a good support for stored procedures;

      Visual Studio provides integrated tools for visualization;

      It can be well integrated with the ASP.NET, WPF, WCF, WCF Data Services.

 

Two, ORM

 

        Common ORM framework:

     ORM is not a product, is the general term framework, object-oriented programming language mapping to relational databases.

          So that programmers can use both the ease of use of object-oriented languages, and can make use of the advantages of relational database technology to achieve the application of additions and deletions to change search operation.

    1. NHibernate: Hibernate version of the .NET platform

    2. iBatis.NET:iBatis achieve the .NET platform

    3.Linq to SQL (Microsoft no longer updated) :. NET ORM framework for the SQL server

    4.ADO.NET Entity Framework: Microsoft's model-driven development in the field of .NET4.0 launch.

Note: ADO.NET Entity Framework is Microsoft's ADO.NET developed based on the object-relational mapping solution, but is ADO.NET was a higher level package.

 

    Background:

     1 , database code repetitive operations

    When we use the three-tier architecture, using ADO.NET to access the database, we will ADO.NET for database operations packaged in a SQLHelper, and then call SQLHelper achieve operation of the database through the D layer. Even with SQLHelper encapsulation, our data access layer (the DAL), or to be repeated for many different business add, delete, change, search operation. Just because of the different operating tables, we'll repeat these CRUD operations, then there is no tool can automatically generate these statements?

 

    2 , affect the scalability and flexibility

    Data access layer simultaneously with the domain model and the relational database model binding, regardless of the domain model or the relational database model changes, you must modify the program code database access layer, increasing the difficulty of maintaining the software.

 

     definition:

    ORM full name: (Object-in the Relation Mapping) that is an object - mappings. ORM is traffic data in a relational database manifested in the form of objects, and object-oriented objects organized manner, the system implementation process business logic.

 

    The main problem is solved ORM object-relational mapping. Generally, the entity correspondence table of our library with an entity like a row of data in the table, the operating entity treated as operations on the table, more concise by ORM model of our code, we'll database after the conversion is performed by operating ORM, ORM model does improve the efficiency of our development.

 

  structure:

    

  From this figure, it can be seen,

      O Customer class corresponding program, is the object,

      R meaning Relation, the corresponding relationship among the data tables

      M represents a mapping between the program and the database objects in relational tables (Mapping is actually an XML file)

 

 

 

 

    When we performed the CRUD database through the application, by way of EF, in fact, the operation of the ObjectContext, EF ObjectContext corresponding to the entrance, to get the corresponding message ObjectContext (CRUD), by the Mapping ORM to the object O mapped to a relational database R. Mapping content stored in our next through a screenshots.

 

 

Object-relational mapping


   Database users table, work table

  

The first step: The system inserts a message into the database, then there is the User object in memory

Step two: how communication and database objects, namely how the object into the database

   XML configuration files need to be configured to save a mapping relationship

The third step: the need for mapping between using Relation (table mapped to each field), and finally generate a complete SQL statement

 

Object: represents the system corresponding table

Table: representative of the database table, wherein the table contains the fields

 

Note: ORM frame using metadata to describe the details of object-relational mapping metadata in XML format is generally used, and specific objects stored in a mapping file. As long as the persistent class information and the mapping relationship table, the ORM reference frame during operation can mapping file, the object persistence to the database.

 

Reflected in the system:

     SSDL: a database (data table)

     CSDL: C # (category)

     CS: mapping between classes and tables

 


----------------
Original link: https: //blog.csdn.net/gxq741718618/article/details/41879617

 

Guess you like

Origin www.cnblogs.com/sheng518/p/11434223.html