A preliminary understanding of EF, a preliminary understanding of English

Source: Internet
Author: User

A preliminary understanding of EF, a preliminary understanding of English

EF: EntityFrameWork is a framework (the so-called framework can be understood as directly using code already written by others), and this framework is an ORM framework (Object/Relation Mapping ).

First, let's talk about how I understand EF at this stage. EF uses the object-oriented idea to operate databases. It can generate an object for tables in databases, the fields in the table correspond to the attributes of the generated object, so that you can directly use the object-oriented idea to write code in the program to operate the database, so that you can not use SQL statements. In this case, we use the object-oriented idea to operate databases through EF. What is the relationship between this and the database operations we have learned before using ADO.net?

First, let's look at a figure. EF and ADO.net both exist, and EF does not directly operate databases instead of ADO.net, in fact, we can use the object-oriented idea to operate the database through EF in the application, while EF still needs to generate SQL statements and finally operate the database through ADO.net.


So there will be a lot of tables in our database, and each table will have a lot of fields. How does EF map the table to the object during class generation? When we create the "ADO.net Object Data Model" in VS, the extension is generated. to open an edmx file, we can change it to xml, the XML file contains the statements indicating the ing between databases, object objects, and databases and object objects. The XML file can map database tables and object objects.


In the last generated. an extension after the edmx file is created. tt is the legendary t4 template. The generated code is included in the t4 template. Some modifications made here can be directly reflected in the generated object.


The code above is used to generate attributes in the t4 template. The comment "// generate attributes" is added by myself, the final response is like this in the specific generated class. The t4 template can control the class generation.

 

Summary

EF has a rough understanding of it for the first time. It appeared after ADO.net and is more in line with the object-oriented thinking. After you have a preliminary understanding of it, you need to know how it is helpful, so you need to learn more.

 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.