This paper expounds the basic concepts related to the mapping between object and database, and how to implement the method of automatic mapping from relationship to object in Vs+sql server environment.
I. INTRODUCTION of ORM
Object-Relational mapping (objects relational Mapping, referred to as ORM, also called O/R Mapping) is a technique to solve the mismatch between object-oriented and relational databases. In a nutshell, ORM automatically persists objects in a program to a relational database by using metadata that describes the mapping between the object and the database.
Reference: http://www.cnblogs.com/wgbs25673578/p/5140482.html
Ii. the ADO. NET Entity Framework
The ADO Framework is an object-relational (ORM) solution developed by Microsoft based on ADO and is now included in Visual Studio Service Pack 1 and. NET Framewor Published in K 3.5 Service Pack 1.
. NET data access, from a large perspective, the design of data access is basically the following categories:
1. DataSet
2. The handwriting code interacts with the database through the Ado.net2.0 connection class
3. ORM Components
Reference: http://www.cnblogs.com/xuf22/articles/5513283.html
Third, ORM components: the ADO Entity Framework
As a technology leader in next-generation data access. The design of the Entity framework preserves high scalability in many places. One of its most important improvements is the flexibility of its mapping definition. As can be seen from the diagram, the Entity Framework can be used to fully define the entities that are mapped to the database table and use the entity directly for the business logic layer or as a data contract for the service. The advantages of entity design over other technologies are reflected in the following areas: Creating complextype (in the CSDL section); EntitySet inheritance.
With the Entity Framework, it is possible to place the design of a solid class entirely in the design of the EDM without having to manually write some very similar code, and the entity model (included in the EDM) can be modified and enforced at run time. In addition, the number of developers working directly with the database will be greatly reduced, most of the time developers only need to manipulate the entity model, the framework will automatically complete the operation of the database.
Reference: http://www.cnblogs.com/lsxqw2004/archive/2009/05/31/1495240.html
Iv. ADO Entity Framework:code First
Tell me about the evolution of EF from its inception to the current years. In the original version of EF, as an ORM component, it configures the mapping between the database and the entity class through the EDM file (which is some XML), enabling the control of the data to and from the database. The original version only supported database first, which generated the EDM from the existing databases structure and then obtained the entity class. Later, EF began supporting model first by building the EDM and then generating the database at version 4.0.
At the beginning of the 4.1 release, EF had the biggest change--starting with the code first model, and it was worth noting that the code was not the same as the concept of database first or model one, but rather the concept of the EDM side. Using code first eliminates the need for the EDM to maintain the mapping between the entity and the database, which is done entirely through the codes, and establishes a mapping model in memory when the program starts running, which is the meaning of code in the name code.
Using code first establishes the entity and then configures the entity-to-database mapping through the codes, then builds the database (if the database already exists, you do not need to build the database, you can directly build the code mapping model), which is called Model first mode. Of course, code first also supports database first, which generates entities from an existing database, as well as the codes for entity mapping databases.
Reference: http://www.cnblogs.com/lsxqw2004/p/4701979.html
V. Using EntityFramework Reverse POCO Generator to implement Code first reverse generation entity model
Usage environment: VS2015 + SQL Server
1. Install entityframework Reverse POCO generator.vsix
2. In the VS Project, quote EntityFramework
3. In the VS Project, the new item
When you are new, the following files are automatically generated:
4, install Dbcontent-tangiblet4editorplusmodellingtoolsvs2015.msi (make the code inside the Dbcontent.tt highlighted).
5. Open Dbcontent.tt, modify the configuration:
6. Open Appconfig, modify the configuration:
7. Save Dbcontent.tt to map the database relationship to the VS entity model (view in DBContent.cs)
VS2015 + SQL Server Reverse build entity model