我是MVC 3的新手,正在努力让Entity Framework 5工作。 (我尝试炸弹的所有恶魔 - 所以,我最终甚至尝试了在http://msdn.microsoft.com/en-us/data/jj206878的VS2010内链接到的控制台演示
我已经引用了'EntityFramework 5.0.0'。
我在演示中使用了SQL Express(但是必须手动设置表格,因为脚本不能在VS2010中运行,而“查询”会打开设计师)。
但是,当我仔细按照本MSDN控制台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注入攻击的SQL Server 2005数据库,我希望使用带有响应式设计的HTML 5和CSS3的MVC 3进行改造 - 但我仍然坚持找到任何一个使用实际工作的MVC中的现有数据库的方法。
答案 0 :(得分:1)
我让它在VS2010
上工作,但也有关于实体框架问题的大戏。
在提出DbContext
搜索结果时,Nuget存在不一致之处。此外,为VS2010安装SP1
也有帮助。
我的默认语言最初设置为VB.NET,必须将其更改为C#才能使演示正常运行。
答案 1 :(得分:0)
我无法回答我自己的问题,但是在编辑了我的问题后,我找到了一个可能的原因来修复我从侧边栏复制并改为我的网址的误导性链接指令 - (没有显示并且同时改变了标签,使其比C#更合适 - (我最终选择了绝大多数完全不合适的标签,只是为了在我们慢速的互联网连接超时之前发布帖子)。
我曾尝试使用 实体框架 作为标记但我的帖子无法上传,因为我被告知我没有足够的学分来创建新标签和C#是我唯一能看到的半可用标签。
然而,在我编辑后尝试将Entity-Framework作为新标记后,我遇到了几个Entity-Framework版本,而entity-framework-5有一个关于使用Framework 4.5的注释(我仍在使用Framework 4) )。
在通过NuGet获取实体框架时,我注意到没有提到要求框架4.5 - 它只是给了我实体框架5,我认为至少我会有最新版本! (我刚看了一眼,它列出了“没有依赖”!!!)
现在看起来我需要卸载Entity Framework 5并获得旧的Entity Framework for Framework 4,然后它可能有机会工作!
PS - 我无法卸载Entity Framework 5,但确实设法追踪最新的稳定版本是4.3.1,虽然我无法通过NuGet获得,但我确实设法通过命令行 - 并且看到 - 上面列出的所有9个错误都消失了,突然控制台实体框架演示工作了 - 最后!