2

我是新來的MVC 3,並且努力讓實體框架5工作。 (ALL的demoes我嘗試炸彈 - 所以,我最終甚至試過被鏈接到從內VS2010在http://msdn.microsoft.com/en-us/data/jj206878SDN實體框架控制檯演示不能編譯

我已經有「的EntityFramework 5.0.0」參考控制檯演示

我用SQL。 Express中的演示(但不得不手動設置表格,因爲腳本不會在VS2010中運行,「查詢」打開設計器)

但是,當我仔細地按照此MSDN中的所有步驟Console EF Demo,我收到以下9個錯誤:

Error 1 'DatabaseFirstSample.BloggingContext' does not contain a definition for 'SaveChanges' and no extension method 'SaveChanges' accepting a first argument of type 'DatabaseFirstSample.BloggingContext' could be found (are you missing a using directive or an assembly reference?) C:\vb08sbs\DatabaseFirstSample\DatabaseFirstSample\Program.cs 15 12 DatabaseFirstSample 
Error 2 'DatabaseFirstSample.BloggingContext': type used in a using statement must be implicitly convertible to 'System.IDisposable' C:\vb08sbs\DatabaseFirstSample\DatabaseFirstSample\Program.cs 9 14 DatabaseFirstSample 
Error 5 'object' does not contain a constructor that takes 1 arguments C:\vb08sbs\DatabaseFirstSample\DatabaseFirstSample\BloggingModel.Context.cs 19 15 DatabaseFirstSample 
Error 4 The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) C:\vb08sbs\DatabaseFirstSample\DatabaseFirstSample\BloggingModel.Context.cs 16 44 DatabaseFirstSample 
Error 6 The type or namespace name 'DbModelBuilder' could not be found (are you missing a using directive or an assembly reference?) C:\vb08sbs\DatabaseFirstSample\DatabaseFirstSample\BloggingModel.Context.cs 23 49 DatabaseFirstSample 
Error 8 The type or namespace name 'DbSet' could not be found (are you missing a using directive or an assembly reference?) C:\vb08sbs\DatabaseFirstSample\DatabaseFirstSample\BloggingModel.Context.cs 28 16 DatabaseFirstSample 
Error 9 The type or namespace name 'DbSet' could not be found (are you missing a using directive or an assembly reference?) C:\vb08sbs\DatabaseFirstSample\DatabaseFirstSample\BloggingModel.Context.cs 29 16 DatabaseFirstSample 
Error 3 The type or namespace name 'Infrastructure' does not exist in the namespace 'System.Data.Entity' (are you missing an assembly reference?) C:\vb08sbs\DatabaseFirstSample\DatabaseFirstSample\BloggingModel.Context.cs 14 30 DatabaseFirstSample 
Error 7 The type or namespace name 'UnintentionalCodeFirstException' could not be found (are you missing a using directive or an assembly reference?) C:\vb08sbs\DatabaseFirstSample\DatabaseFirstSample\BloggingModel.Context.cs 25 23 DatabaseFirstSample 

我很明顯錯過了一些東西 - 但是,我可能會非常感謝一些幫助。

另外,我知道EF導致明顯的膨脹,並因此而緩慢,並建議避免使用EF並僅使用數據類 - 但我找不到任何解釋如何使用這種方法的方法作爲使用EF的更有效的替代方案(因爲EF方法似乎被推到MS站點的任何地方)。

我繼承了一個傳統的ASP應用程序,它使用SQL Server 2005數據庫,最近受到SQL注入攻擊,我想使用具有響應式設計的HTML 5和CSS3使用MVC 3進行改造 - 但我一直在尋找在MVC中使用現有數據庫的任何實際工作方法。

回答

0

我無法回答我自己的問題,但在編輯我的問題以修復從邊欄複製並更改爲我的網址的錯誤鏈接指令後,我找到了一個可能的原因 - (它沒有正確顯示),並且同時更改了標籤,而不僅僅是C# - (我最終選擇了絕大多數完全不合適的標籤,以便在我們的Internet連接超時之前發佈該帖子) 。

我曾試圖用實體框架作爲標籤,但我的文章無法上傳,因爲我被告知,我沒有足夠的學分,以創建一個新的標籤和C#是唯一的半可用的標籤,我可以看到選擇。

但是,在編輯完Entity-Framework作爲新標籤之後,我遇到了幾個實體框架版本,而entity-framework-5有關於使用Framework 4.5的說明(我仍然在使用Framework 4)。

沒有提及需要通過NuGet獲取實體框架時需要的框架4.5 - 它只是給了我實體框架5,我認爲至少我會有最新版本! (我只是再看一遍,它列出了「沒有依賴」!!!)

現在看來我需要得到實體框架5卸載並獲得舊的實體框架框架4,然後它可能有一個工作的機會!

PS - 我無法卸載Entity Framework 5,但確實設法追查到最新的穩定版本是4.3.1,雖然我無法通過NuGet獲得,但我確實設法通過NuGet安裝它命令行 - 而且瞧瞧 - 上面列出的所有9個錯誤都消失了,終於突然終止了Console Entity Framework演示!

+1

你是如何安裝的實體框架5?你使用了nuget嗎?如果沒有,你應該使用nuget。安裝EF5最簡單的方法就是創建一個新項目並在程序包管理器控制檯(工具 - >程序包程序包 - >程序包管理器控制檯)中執行「Install-Package EntityFramework」命令。如果你沒有包管理器控制檯,你可以從http://nuget.org/(安裝NuGet)安裝它。實際上,NuGet的EF5位同時適用於.NET Framework 4和.NET Framework 4.5。如果您的目標是.NET Framework 4,那麼4.5中引入的一些功能(枚舉,空間)將會丟失。 – Pawel

1

我得到它的上VS2010工作,但大劇實體框架的問題,太。

在提出DbContext搜索的結果時,Nuget中存在不一致。另外,VS2010安裝SP1幫助爲好。

我有我的默認語言最初設置爲VB.NET,必須更改爲C#才能使演示工作。