安装Entity Framework【Setup Entity Framework Environment】(EF基础系列篇4)

本文介绍如何安装并使用Entity Framework 6.0 (EF6.0) 创建一个简单的实体数据模型。首先需要安装.NET Framework 4.5、Visual Studio 2012及以上版本以及MSSQL Server 2005及以上版本。接着通过NuGet包管理器安装Entity Framework 6.0,并以SchoolDB样例数据库为模板创建实体数据模型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Entity Framework 5.0 API是分布在两个地方:NuGet和.NET Framework中,这个.NET framework 4.0/4.5包含EF核心的API,然而通过NuGet包获取的EntityFramework.dll包含EF 5.0特别的特性;EF6.0中不是分开的:

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

在这个基础的系列课程中,我将会使用EF 6.0,这个最新的EF版本来学习,

学习EF,首先要安装下面的工具:

.NET Framework 4.5

Visual Studio 2012/2013/2015

MS SQL Server2005/2008/2012/2014 Express

下面我们来看看怎么安装EF吧:

我们打开VS2012新建项目:

然后,我们选中“项目名称”,点击右键,选择“管理Nuget程序包”,在弹出来的界面中,输入:"EntityFramework",会自动查询到EntityFramework,然后点击安装,按照我下面的图示进行就可以了:

安装完成之后,是这样的:然后关闭这个窗口就行了。。。

 

创建数据库:

这个系列课程中,我将会使用SchoolDB样例数据库,它包含数据表,存储过程,和视图;数据库的设计如下:

 

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.

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.

 

在这个数据图表中,我们可以看到,不同表之间的关系:

一对一:Student and StudentAddress表之间是一对一的关系,例如一个Student有0到1个的StudentAddress;

一对多:Standard and Teacher表之间是一对多的关系,例如很多Teacher关联一个Standard;

多对多:Student and Course表之间是多对多关系,通过中间表StudentCourse 联系在一起,例如;一个学生可以选择很多课程,同时一个课程可以有很多学生来选择;

 

好了,EF的安装就到此,相信大家已经学会了,后面一节我将要学习一个简单的实体数据模型来创建数据库。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值