I was contacted in 2014 EF, used for more than a year, feel very convenient, now the company did not use, recently a friend took two projects to find me to help, all want to use EF, their own time has not been used, through this opportunity to review.
The Entity framework, referred to as EF, is the Microsoft-based database access technology, which is a set of ORM frameworks, so let's start with an ORM.
I. INTRODUCTION of ORM
The object-relational mapping (objects relational Mapping, ORM) pattern is a technique to solve the mismatch between object-oriented and relational databases. Simply put, ORM is by using the Description object and the database between
Mapped metadata that automatically persists objects in the program to the relational database. So, how exactly is persistence achieved? A simple solution is to use hard-coded methods to provide a separate method for each possible database access operation.
This scenario has the following disadvantages:
1. Persistence layer lacks elasticity. The interface of the persistence layer must be modified in the event of changes in business requirements
2. Persistence layer with the domain model and the relational database model binding, regardless of the domain model or the relational database model changes, poison modification persisted once the related program code, increased the software maintenance difficulty.
ORM provides another pattern for implementing a persistence layer, which uses mapping metadata to describe the mapping of object relationships, enabling ORM middleware to act as a bridge between the business logic layer and the database layer of any application. Java's typical ORM middleware has
: Hibernate,ibatis,speedframework.
The ORM methodology is based on three core principles:
· Simple: Model data in the most basic form.
· Communication: The database structure is documented in a language that anyone can understand.
· Accuracy: Create a properly standardized structure based on the data model.
Second, the concept of ORM
Let's start with the O/R. The letter O originates from "object", and R is derived from "relationship" (relational). In almost all programs, there are objects and relational databases. In the business logic layer and the user interface layer, we are oriented towards the
The elephant. When the object information changes, we need to keep the object's information in the relational database.
When you develop an application (do not use O/R Mapping), you may write a lot of data access layer code to save, delete, read object information from the database, and so on. You wrote a lot of ways to read object data in the DAL.
, change the status object, and so on. And the code is always repeating itself.
The main problem with ORM resolution is the mapping of object relationships. The domain model and the relational model are based on the conceptual model, respectively. The domain model is object-oriented, and the relational model is relationship oriented. In general, a persisted class and a table
Corresponding, each instance of the class corresponds to a record in the table, and each property of the class corresponds to each field of the table.
ORM Technical Features:
1. Improved development efficiency. Since ORM can automatically map the fields and properties of the entity object to the table in the database, we may not actually need a dedicated, large data access layer.
The 2.ORM provides a mapping of the database, without the direct encoding of SQL, to fetch data from the database as if it were an object.
Third, the advantages and disadvantages of ORM
The disadvantage of ORM is that it sacrifices the execution efficiency of the program and the fixed thinking mode.
From the system structure, the use of ORM system is generally multilayer system, the level of the system is more, the efficiency will be reduced. ORM is a complete object-oriented approach, and the object-oriented approach can have a certain impact on performance.
When we develop systems, there are generally performance issues. Performance problems are mainly caused by incorrect algorithms and incorrect use of the database. The code generated by ORM is generally less likely to write efficient algorithms, and in database applications it is more likely to
Misuse, mainly embodied in the extraction of persistent objects and processing of data, if the use of ORM, the programmer is likely to extract all the data into the memory object, and then filter and processing, so that the performance problems are easy to produce.
When you persist an object, the ORM generally persists all properties, and sometimes this is not desirable.
But ORM is a tool that can really solve some repetitive labor.
The advantages of ORM: rapid development, easy to transplant database, the advantages are certainly not only these two, I only said I think the more important two.
01-EF, ORM Introduction