Entity Framework learning notes-EF introduction (an article tells you what EF is), entity learning notes

Source: Internet
Author: User

Entity Framework learning notes-EF introduction (an article tells you what EF is), entity learning notes

Entity Framework is a data-oriented "Entity Framework" based on ADO. NET ". EF.

 

It converts each database object to an application object (entity) by using the abstract data structure, and converts all data fields to properties ), the relationship is converted to association, so that the E/R Model of the database is fully converted into an object model, so that the programmer can use the most familiar programming language to call access.

I personally think that the typical explanation of EF in the encyclopedia is that it allows upper-layer application codes to access data in an object-oriented manner.

In the past, we used to directly read databases and use DataSet, able, and so on to transmit values in business data, resulting in ugly code and a serious departure from the idea of OO.

For example, when we store objects in a database, the Entity Framework is mainly used to help us store objects in the database (that is, "Dealing" with the database through objects "), as long as the object is handed over to the Entity Framework and you do not need to write SQL statements by yourself, it will help us automatically generate SQL statements. The SQL statements generated here are sent to the database through ADO.net, that is, the database is operated through ADO. so the first sentence in this article says "EF isBased on ADO. NET, Data-oriented 'entity framework '".

The specific process can be expressed as follows:

For example, if you want to store two entities in the memory, Student and Teacher, in the database, EF will automatically map the entities through EDM and store an entity as a record to the database, how does EF determine which object should be stored in which table and which attribute should be stored in which field? This is where the ing is powerful:

In Visual Studio, ing is embodied through the. edmx file. The essence of the. edmx file is an XML file, which is used to define the concept model, storage model, and ing between these models.

For example, the ing in the preceding example can be reflected in the following format:

1 <! -- CSDL indicates the Entity here --> 2 <Entity Name = "Student"> 3 <Pro Name = "StuName"> 4 <Pro Name = "StuSex"> 5 <Pro Name =" stuAge "> 6 </Entity> 7 8 <! -- SSDL indicates the database Table --> 9 <Table Name = "Student"> 10 <Col Name = "StuName"> 11 <Col Name = "StuSex"> 12 <Col Name = "StuAge"> 13 </Table> 14 15 <! -- C-S here represents the ing between entities and database tables --> 16 <Relation Entity = "Student" Table = "Student"> 17 <Rel ProName = "StuName" ColName = "StuName"> <! -- StuName field in the table corresponding to the StuName attribute in the object --> 18 <Col ProName = "StuSex" ColName = "StuSex"> 19 <Col ProName = "StuAge" ColName = "StuAge"> 20 </Relation>

The above code is not the exact format in the. edmx file. For a brief description, you can refer to it as "pseudo code". The creation and basic format of the. edmx file will be briefly introduced later.

 

 

We can see from the above that, from the perspective of reading code, EF can be well understood without understanding the data structure. From the perspective of implementation, EF can make the storage "modeled", just like storing many objects in a List, each instance is stored in the database table, and all instances are obtained from the database. The program interacts with the database and corresponds to OO code, making it easy to "Dock ".

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.