文章出處

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的安裝就到此,相信大家已經學會了,后面一節我將要學習一個簡單的實體數據模型來創建數據庫。

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()