Entity Framework learning notes (1)

Source: Internet
Author: User

Please indicate reprinted address: http://www.cnblogs.com/arhatHaha! Old Wei came back and updated the content in February. Because he was working on a project in February and had no time to write it, Old Wei will try to write as many things as possible in February. Therefore, the content of February is mainly EF and Linq. As for NHibernate, it will be updated later. 1. EF Introduction

The full name of EF is Entity Framework, which is an ORM Framework launched by Microsoft. It has the same role as nhib.pdf, but it must be compatible with Microsoft. Although EF is a late product, its features are very good. It is much simpler than nhib.pdf. For example, we don't need to write those ing files. All right, let's get started with how to use EF.

As for EF knowledge, Old Wei will make up later, because Old Wei is not very happy that edmx files put the ing files and entity files together, which is not conducive to hierarchical design.

Today, I will write out the Old Wei's EF separation experience, otherwise I will forget it later! (Khan, old man !)

Ii. Establishment of EF separation Environment

Here, Old Wei uses the MySql database. Why is it not necessary to use SQL Server? It is mainly because Old Wei cannot afford the damage! So when he learned EF, he had a lot of detours!

First, we will build a "Com. ArHat. EF" solution and create four projects in the solution:

1. Com. ArHat. DAL (Class Library)

2. Com. ArHat. BLL (Class Library)

3. Com. ArHat. Model (Class Library)

4. Com. ArHat. Test (console application)

And add mutual references between them ).

Then we save the tt file and we will find that the School. Context. cs file has content again. But it is indeed wrong during compilation.

DAL. SchoolEntities context = List <Model. student> query = stu query. ToList <Model. student>

Test the code in the main project Com. ArHat. Test as follows:

  Main(=  (Model.student stu 

Run the following command to check the effect:

Oh, no. How can I report an error? Why? In fact, the problem is that when the program is running, it is to find the App in the main project. config file, and our link string is generated in the Model project, so it cannot be found when the program is running. The solution is to set the App in the Model. copy the config file to the main project. Then let's test it.

The exciting time has finally arrived. We have succeeded! Haha. In fact, this is nothing. Through the above steps, we know how to divide the edmx file into two parts: an object class and a DbContext. This achieves our goal of layering.
Now, let's get here today!

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.