[Original] Entity Framework query principle, entityframework
Preface
The full name of Entity Framework is ADO. NET Entity Framework, which is an ORM (Object/Relational Mapping) Framework developed by Microsoft Based on ADO. NET.
Main features of Entity Framework:
1. Support for multiple databases (Microsoft SQL Server, Oracle, and DB2 );
2. The powerful ing engine can well support stored procedures;
3. Provides Visual Studio integrated tools for Visual operations;
4. Excellent integration with ASP. NET, WPF, WCF, and WCF Data Services.
Thinking? With EF, we don't have to write SQL statements by ourselves. What exactly does EF do? Let's explore it?
We know that the edmx file is the metadata of EF, so we can open the EDMX file in XML mode and see the following data:
The SSDL in the figure represents the configuration node for the database, the CSDL entity configuration node, and the C-S entity-to-database relationship ing.
We found that the XML data of the GroupInfo node in the SSDL configuration node is consistent with the data in our data. For example
SSDL indicates GroupInfo in the configuration node of the database.
GroupInfo in the csdl object configuration Node
GroupInfo in the grouping between C-S entities and databases
After learning about this, let's see how EF generates SQL statements.
Private void button#click (object sender, EventArgs e) {// 1.0 instantiate the object PhoneBookEntities db = new PhoneBookEntities () of the EF context container class (); // 2.0 query the ID in GropuINfo <209 all data databases. groupInfo. where (c => c. groupId <209 ). toList (). forEach (c => Console. writeLine (c. groupName ));}
We can see from the code and analysis diagram in:
1. EF is tightly packaged, and it is still necessary to call Ado. NET at the underlying layer.
2. EF is only responsible for generating SQL statements and sending them to Ado. NET. Ado. NET is responsible for reading data from the DB and finally returning the EF
3. The edmx metadata in EF obtains the structure description of the DB table.
4. the query SQL statement select GroupId, GroupName, and GroupType from GroupInfo that can obtain the where condition from the metadata can be provided by our c => c. GroupId <209
The mystery of EF has been uncovered ~~~
If you feel good after reading this article, click 【Follow] To support the blogger. Thank you!
If you feel good after reading this article, click
[Recommended]
Author:Feng Xiaoyi
QQ: 616931
Source:Http://www.cnblogs.com/fenglingyi
Statement:The copyright of this article is shared by the author and the blog Park. This statement must be retained without the author's consent and the original article connection must be clearly provided on the article page. Otherwise, the legal liability will be retained.