C# MVC 脚手架不支持 Entity Framework 6 或更高版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19165410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MVC scaffolding does not support Entity Framework 6 or later
提问by MrBeanzy
Just upgraded to Entity Framework 6 to take a look. I'm using MVC4.
刚刚升级到 Entity Framework 6 来看看。我正在使用 MVC4。
But i recieve this message when trying to make a controller from a model and context.
但是当我尝试从模型和上下文制作控制器时收到此消息。
MVC scaffolding does not support Entity Framework 6 or later
MVC 脚手架不支持 Entity Framework 6 或更高版本
采纳答案by 5had3sofQu4rtz
Thought this could use some expanding :) As mentioned above ASP.NET MVC 4 scaffolding does not support EF6 or higher. This means that an older EF, compatible with MVC 4 will have to be installed. To do this:
认为这可以使用一些扩展:) 如上所述,ASP.NET MVC 4 脚手架不支持 EF6 或更高版本。这意味着必须安装与 MVC 4 兼容的旧 EF。去做这个:
- Open the Package Manager Console:
- select TOOLS -> Library Package Manager -> Package Manager Console
In the Package Manager Console, uninstall the current EF package by executing the following command:
UnInstall-Package EntityFramework -Version <version number>
*Where
<version number>
is the version number of the EF currently installed.
*NOTE: to find out what EF version is installed, run the following command in the Package Manager Console:Get-Package EntityFramework
To avoid potential metadata problems the providers entry in the Web.config file will need to be removed:
- Open the Web.config file in the project directory.
Delete the following lines:
<providers> <provider invariantName=System.Data.SqlClient type=System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer /> </providers>
Now, in the Package Manager Console Execute the following command to install Entity Framework 5.0.0:
Install-Package EntityFramework -Version 5.0.0
- 打开包管理器控制台:
- 选择工具 -> 库包管理器 -> 包管理器控制台
在包管理器控制台中,通过执行以下命令卸载当前的 EF 包:
UnInstall-Package EntityFramework -Version <version number>
*
<version number>
当前安装的EF版本号在哪里。
*注意:要找出安装的 EF 版本,请在包管理器控制台中运行以下命令:Get-Package EntityFramework
为了避免潜在的元数据问题,需要删除 Web.config 文件中的提供者条目:
- 打开项目目录中的 Web.config 文件。
删除以下几行:
<providers> <provider invariantName=System.Data.SqlClient type=System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer /> </providers>
现在,在包管理器控制台中执行以下命令来安装 Entity Framework 5.0.0:
Install-Package EntityFramework -Version 5.0.0
回答by MrBeanzy
After a bit more digging
再挖一点之后
ASP.NET MVC 4 scaffolding does not support Entity Framework 6 or higher. Support of scaffolding of Entity Framework 6 is targeted for the next release of ASP.NET MVC.
ASP.NET MVC 4 脚手架不支持实体框架 6 或更高版本。对 Entity Framework 6 脚手架的支持是针对 ASP.NET MVC 的下一个版本。
So looks like ill wait until MVC 5 is properly released
所以看起来很不舒服,直到 MVC 5 被正确发布
回答by Bryan Weaver
ASP.NET MVC 4 scaffolding does not support Entity Framework 6 or later. Support for scaffolding will be included in MVC5. Work around is to use EF5 for scaffolding and then upgrade to EF6.
ASP.NET MVC 4 脚手架不支持实体框架 6 或更高版本。对脚手架的支持将包含在 MVC5 中。解决方法是将 EF5 用于脚手架,然后升级到 EF6。
回答by Pinte Dani
Workaround which worked for me to scaffold controllers and views for MVC 4and EF 6:
对我有用的解决方法为MVC 4和EF 6搭建控制器和视图:
- Use an EXISTING OR NEW MVC 5Project and copy the Entity Data Modelfor which you want to create your scaffolding in MVC 4.
- Add the Entity Data Modelto your MVC 5DBContext
- Create your scaffolded controller and views in the MVC 5Project which obviously works with EF 6.
- Copy the generated views from MVC 5to your old MVC 4Project
- 使用现有或新的MVC 5项目并复制 要在MVC 4 中为其创建脚手架的实体数据模型。
- 将实体数据模型添加到您的MVC 5DBContext
- 在显然适用于EF 6的MVC 5项目中创建您的脚手架控制器和视图。
- 将生成的视图从MVC 5复制到旧的MVC 4项目
This is a solution to generate scaffolding if you do not want to downgrade the EF Version.
如果您不想降级 EF 版本,这是生成脚手架的解决方案。
For me this worked out of the box
对我来说,这是开箱即用的