ADO. NET Entity Framework getting started example wizard 1

Source: Internet
Author: User

ADO. NET Entity Framework is an entity framework introduced by. NET Framework 3.5 SP1. It allows developers to focus on data through the Object Model (rather than the logical/Relational Data Model. The Entity Framework uses the concept layer, ing layer, and logic layer to abstract the logical database structure. This article http://forum.entlib.com Open Source Forum team provides.

Entity Data Model (Entity Data Model)

The core of an object framework lies in its model. The Entity Framework supports logical storage models that represent relational architectures in databases. Relational databases usually store data in different ways than applications use data. Generally, this forces developers to retrieve data based on the structure of the database containing data. Therefore, developers usually load data into business entities that are more suitable for processing business rules. In this example, the relational database architecture is represented by a logical model, and the business entity represents the conceptual model. The Entity Framework uses the ing layer to build bridges between models. Therefore, the Entity Framework Model has three active layers:

1. Concept layer (conceptual layer)-a conceptual model that represents data, including entities and relationships.

2. logical layer-describes the data storage model in the database.

3. Mapping layer-establishes a ing between the concept layer and the logic layer model.

These three layers allow you to map data from a relational database to a more object-oriented business model. The Entity Framework provides methods to define these layers using XML files. It also generates a series of classes based on the conceptual model architecture. You can program these classes to directly interact with data. This provides an abstraction level, so developers can program conceptual models rather than relational models.

The following shows how to use entity framework to build an example program.

First, useEntity Data Model WizardCreate the following northwinddb. edml file.

Conceptual Model and Logical Model View:

This example uses the northwind sample database. The following code is used to add, delete, modify, and query the MERs table.

1.Add MERsRecord

Using (northwindentities mydb = new northwindentities ())

{

Customers customer = new customers ();

Random Rm = new random ();

Customer. customerid = "A" + RM. Next (9999). tostring ();

Customer. companyName = "entlib.com Forum ";

Customer. Address = "http://www.EntLib.com ";

Mydb. addtocustomers (customer );

Int COUNT = mydb. savechanges ();

Txtcustomerid. Text = Customer. customerid;

}

2.Update MERsRecord

Using (northwindentities mydb = new northwindentities ())

{

VaR query = from customer in mydb. MERs

Where customer. customerid = txtcustomerid. Text. Trim ()

Select customer;

Foreach (VAR row in query)

{

Row. companyName = "updated company name ";

}

Mydb. savechanges ();

}

3.Delete MERsRecord

Using (northwindentities mydb = new northwindentities ())

{

VaR query = from customer in mydb. MERs

Where customer. customerid = txtcustomerid. Text. Trim ()

Select customer;

Foreach (VAR row in query)

{

Mydb. deleteobject (ROW );

}

Mydb. savechanges ();

}

4.Query MERs, Returns all records

Using (northwindentities mydb = new northwindentities ())

{

Datagridview1.datasource = mydb. MERs MERS;

}

Run the following Entity Framework demo program:

This sample program is provided by the http://forum.entlib.com open source ASP. NET Forum team. If you have any questions or questions, please visit the http://forum.entlib.com forum.

Attachment:
Entityframeworkdemo.rar78 KB,

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.