我是新來的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中使用現有數據庫的任何實際工作方法。
你是如何安裝的實體框架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