Setup Entity Framework Environment

http://www.entityframeworktutorial.net/EntityFramework5/setup-entityframework-environment.aspx

Entity Framework 5.0 API was distributed in two places, in NuGet package and in .NET framework.

The .NET framework 4.0/4.5 included EF core API, whereas EntityFramework.dll via NuGet package included EF 5.0 specific features.

This has been changed with EF 6.0 which is included in EntityFramework.dll only and is not dependent on .NET framework.

For the basic tutorials, we will use EF 6.0, the latest version of entity framework as of this writing.

 

Install the following tools to work with entity framework:

  • .NET Framework 4.5
  • Visual Studio 2012
  • MS SQL Server 2005/2008/2012 Express

 

Install EF via Nuget:

You can install entity framework into your project via nuget.

Here, we will install EF (EntityFramework.dll) via nuget in the console application in VS 2012. 

You can install EF via NuGet the same way in any version of Visual Studio.

 

右键项目,然后选择“管理NuGet程序包”

Right click on project in the solution explorer and select Manage NuGet Packages..

然后选择联机,并搜索EntityFramework

This will open Manage NuGet packages dialogue box. Now, select Online in left bar and search for EntityFramework as shown below.

 

最后安装

This will search for all the packages related to Entity Framework. Select EntityFramework and click on Install.

 

Click on the I Accept button in License Acceptance dialogue box. This will start the installation.

After installation, make sure that the appropriate version of EntityFramework.dll is included in the project.

Now, you are ready to use Entity Framework in your project.

 

Setting up the database:

This tutorial will use sample SchoolDB which has different tables, stored procedures and views. The SchoolDB database design is shown below:

You can see in the above diagram that the sample SchoolDB database includes tables with the following relationships, for demo purpose.

  • One-to-One: Student and StudentAddress have a one-to-one relationship eg. Student has zero or one StudentAddress.  
  • One-to-Many: Standard and Teacher have a one-to-many relationship eg. many Teachers can be associate with one Standard.
  • Many-to-Many: Student and Course have a many-to-many relationship using StudentCourse table where StudentCourse table includes StudentId and CourseId. So one student can join many courses and one course also can have many students.

学生和学生地址,是一对一的关系,学生有一个或0个地址

标准和老师,是一对多的关系,一个标准可以针对于多个老师

学生和课程,是多对多的关系,1个学生可以选修多门课程;一门课程,可以有多个学生选修

Download Sample Project for all the tutorials on entity framework.

Let's create first simple Entity Data Model for sample School database in the next section.

 

posted @ 2015-03-02 20:15  ChuckLu  阅读(185)  评论(0编辑  收藏  举报