1. 程式人生 > >vs2010 安裝EF 的幾種方法

vs2010 安裝EF 的幾種方法

背景①:利用NuGet來安裝EFCodeFirst方法

①我們可以利用NuGet包管理器(安裝ASP.NET MVC3時會自動安裝)來把EFCodeFirst類庫新增到我們的Mvc工程中。這個類庫使得我們可以直接使用code-first。點選“工具”選單下的“Library Package Manager”子選單下的“Add Library Package Reference”選單選項;


②點選“Add Library Package Reference”選單選項後,將會彈出一個對話方塊,標題為“Add Library Package Reference”;


③預設狀態下,左邊的“All”選項處於選擇狀態。因為還沒有安裝任何包,所以右邊面板中顯示“找不到任何項”。點選左邊面板中的“online”選項,NuGet包管理器將會在伺服器上檢索所有當前能夠獲取的包;


④伺服器上有幾百個當前能夠獲取的包,現在我們只關注EFCodeFirst包。在右上角的搜尋輸入框中輸入“EFCode”。在檢索結果中,選擇EFCodeFirst包,並且點選Install按鈕安裝包;


⑤點選了install按鈕後,會彈出一個接受許可證視窗,在這個視窗中必須要點選“I Accept”按鈕,接受許可證條款,安裝才能繼續進行。

⑥安裝完畢後,點選close按鈕。我們的Mvc工程中會自動載入EntityFramework程式集,其中包含了EFCodeFirst類庫。

背景②:讓事實說話

今天在Win 7下利用NuGet來安裝EFCodeFirst package時,出現錯誤:This package(or one of its dependencies) contains PowerShell scripts and needs to be installed from the Package Manager Console。

師兄的XP下出現該提示的解決方法是打一個微軟的補丁KB968930,下載地址:

http://www.microsoft.com/downloads/zh-cn/results.aspx?freetext=KB968930&displaylang=zh&stype=s_basic

裡面有XP,Vista,Windows Server 2003及2008的32位,64位版本,但是沒有Win 7版本的,

微軟對該補丁的描述如下:

Windows XP 更新程式 (KB968930)
Windows Management Framework Core 程式包提供了適用於 IT 專業人員的已更新管理功能。

用於 Windows Server 2008 的 Windows PowerShell 2.0 和 WinRM 2.0 (KB968930)
Windows Management Framework Core 程式包包括 Windows PowerShell 2.0 和 Windows Remote Management (WinRM) 2.0。

解決鳥:後來根據提示找到了一個在控制檯進行安裝的解決方法:

①部落格園原文內容如下:

I tried to install EntityFramework 4.1 on VS 2010 through NuGet. I searched and found the package through “Tools > Library Package Manager > Add Library Package Reference” tool and I got this error: “This package (or one of its dependencies) contains powershell scripts and needs to be installed from the package manager console.”. This is what I did to fix it:

Tools > Library Package Manager > Package Manager Console
PM > get-package -remote -filter entityframework
(got some results including EntityFramework 4.1.10311.0)
PM > install-package -id EntityFramework
Successfully added ‘EntityFramework …

②根據提示,在控制檯安裝會出現如下資訊(以下藍色內容為需要輸入的命令):

Each package is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Some packages may include dependencies which are governed by additional licenses. Follow the package source (feed) URL to determine any dependencies.

PM> get-package -remote -filter entityframework

Id Version Description
– ——- ———–
Check_My_Box_Packages 1.1.0.2 This Package uses MvcScaffolding, EntityFramew…
Check_My_Box_Packages 1.1.0.3 This Package uses MvcScaffolding, EntityFramew…
EFCodeFirst 1.0 Legacy package, Code First is now included in …
EFCodeFirst 1.1 Legacy package, Code First is now included in …
EntityFramework 4.1.10311.0 DbContext API and Code First workflow for ADO….
EntityFramework 4.1.10331.0 DbContext API and Code First workflow for ADO….
EntityFramework.Patterns 0.2 Provides different patterns to be used with En…
EntityFramework.Sample 4.1 This sample blog model demonstrates the use of…
EntityFramework.SqlServerCompact 4.1.8482.1 Allows SQL Server Compact 4.0 to be used with …
EntityFrameworkProfiler 1.0.0.839 EntityFramework Profiler is a real-time visual…

PM> install-package -id EntityFramework
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkID=211010. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
已成功安裝“EntityFramework 4.1.10331.0”
已成功將“EntityFramework 4.1.10331.0”新增到 MvcMovie

PM>