Brief Introduction to the EF framework

Source: Internet
Author: User

Entity Framework ADO. NET Entity Framework (EF)

A set of technologies that support data-oriented software application development allow developers to use conceptual models mapped to the logical architecture in the data source.

Entity Data Model (EDM)

A data model is used to define application data as entity and relational sets that can be mapped to the runtime type and storage structure of the common language.

Conceptual Architecture Definition Language conceptual schema definition language (CSDL)

An XML-based language that can be used to define object types, associations, object containers, object sets, and associated sets (entities) of a conceptual model-> Business Objects

Storage Architecture Definition Language store Schema Definition Language (SSDL)

An XML-based language that defines the object types, associations, object containers, object sets, and association sets of a storage model. It often corresponds to the database architecture. (Data Storage Model)

Ing standard language mapping specification language (MSL)

An XML-based language that maps the items defined in the conceptual model to the items in the storage model. (You do not have to worry about how to store data)

ADO. NET Entity Framework is divided into four layers: storage provider, mapping layer, object services, and LINQ to entities.
Storage provider: responsible for direct communication with data sources and supporting database SQL Server
Mapping layer: ing between the database concept layer and the logic layer. Through the EDM model and mapping provider, the application will be built on a higher EDM model abstraction level. At the same time, in the application, the query language of the local database, such as (t-SQL), will no longer be used, instead of Entity SQL.
Object services: Object services aims to eliminate data and application code style mismatch ADO.. Net allows the query results to be displayed as rows and Column records.. Net object. This layer also includes more advanced services supported by the O/R Mapping Framework, such as identity authentication, tracking object status changes, parallel checks, and processing updates.
LINQ to entities: integrates Entity Framework with a LINQ project to provide a query function that is suitable for the object-oriented programming language.
The LINQ to entities layer depends on the two layers of object services and mapping layer.
The Data Access Method of ADO. NET Entity Framework is similar to that of ADO. net.
Ado. Net ADO. NET Entity Framework
Sqlconnection entityconnection
Sqlcommand entitycommand
Sqldatareader. entitydatareader
Sqldataadapter objectcontext
Objectquery <t>
Dataset entity
CSDL, SSDL, MSL
Note: Ado. NET and ADO. NET Entity Framework are different technologies. This comparison is just a helpful comparison.
 
 

Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. windows. forms; using system. data. entityclient; using system. data. objects; namespace mywindowsform {public partial class form1: FORM {public form1 () {initializecomponent ();} private void form1_load (Object sender, eventargs e) {This. region R Idview1.datasource = getallcustomerbyobjectcontextnoesql ();} // Private list in ado.net mode <MERs> getallcustomer () {list <customers> customerlist = new list <customers> (); using (entityconnection Econ = new entityconnection (@ "metadata = Res: // */mymodel. CSDL | res: // */mymodel. SSDL | res: // */mymodel. MSL; provider = system. data. sqlclient; provider connection string = 'data source = .; initial catalog = northwind; user I D = sa; Password = WY; multipleactiveresultsets = false' ") {entitycommand ecmd = new entitycommand (" select value it from northwindentities. customers as it ", Econ); Econ. open (); entitydatareader EDR = ecmd. executereader (commandbehavior. sequentialaccess); While (EDR. read () {customers customer = new customers {address = EDR ["Address"]. tostring (), City = EDR ["city"]. tostring (), Country = EDR ["country"]. tostr Ing (), phone = EDR ["phone"]. tostring ()}; customerlist. add (customer) ;}return customerlist;} // The objectcontext mode ado.net dataadapter dataset mode private ienumerable <MERs> getallcustomerbyobjectcontext () {entityconnection Econ = new entityconnection (@ "metadata = Res: // */mymodel. CSDL | res: // */mymodel. SSDL | res: // */mymodel. MSL; provider = system. data. sqlclient; provider connection string = 'data source =.; Initial catalog = northwind; user id = sa; Password = WY; multipleactiveresultsets = false' "); objectcontext context = new objectcontext (ECON); // equivalent to dataadapter, the data connection objectquery <customers> objquery = context is automatically opened. createquery <MERs> ("select value it from northwindentities. MERs as it where it. customerid = 'cccc' "); // It is equivalent to dataset return objquery. asenumerable <customers> ();} // Private ienumerable without esql <Customers> getallcustomerbyobjectcontextnoesql () {northwindentities northdata = new northwindentities (); Return northdata. MERs. where (S => S. region = NULL ). asenumerable <customers> ();} // LINQ and the 'in' expression private ienumerable <customers> getallcustomerbylinq () {northwindentities northdata = new northwindentities (); vaR query = from customer in northdata. customers select customer; return query. wher E (S => S. region! = NULL). asenumerable <customers> (); // Where (S => S. region! = NULL) for the 'in' expression, you can add the where condition to control data display} private void btnnew_click (Object sender, eventargs E) // Add data {northwindentities northdata = new northwindentities (); customers customer = new customers {customerid = "WY", companyName = "WY"}; MessageBox. show (customer. entitystate. tostring (); northdata. addobject ("northwindentities. customers ", customer); MessageBox. show (customer. entitystate. tostring (); northdata. savechanges (); MessageBox. show (customer. entitystate. tostring ();} private void btndelete_click (Object sender, eventargs e) // delete data {northwindentities northdata = new northwindentities (); MERs customer = northdata. MERs. first (S => S. customerid = "WY"); MessageBox. show (customer. entitystate. tostring (); northdata. deleteobject (customer); MessageBox. show (customer. entitystate. tostring (); northdata. savechanges (); MessageBox. show (customer. entitystate. tostring ();} private void btnchange_click (Object sender, eventargs e) // modify data {northwindentities northdata = new northwindentities (); MERs customer = northdata. MERs. first (S => S. customerid = "WY"); MessageBox. show (customer. entitystate. tostring (); customer. companyName = "Hello World"; MessageBox. show (customer. entitystate. tostring (); northdata. savechanges (); MessageBox. show (customer. entitystate. tostring ());}}}

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.