Entity Framework MVC 5 项目中的 6.0 不工作
Entity Framework 6.0 in MVC 5 project not working
我当前的设置:
VS1013-解决方案
- MvcProject (MVC5)
- FrameworkProject (ClassLibrary) - BaseController、BaseViewModel 等
- EntitiesProject (ClassLibrary) - edmx 仅作为 .cs 文件
- EntitiesProjectIO (ClassLibrary) - InBetweenLayer 以获取基础数据库中的get/set数据
我在 'MvcProject' 中添加了对 'EntitiesProjectIO' 的引用,并调用了 'GetData(...)'。
Schema specified is not valid. Errors: \r\nSurgeryManagementEntities.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
是我收到的消息,我现在知道 *** 是怎么回事了。
我已经添加了对几乎每个已知程序集的引用,并从纯数据库项目 (EntitiesProject) 复制了文件。
还复制了 EntityFramework.dll,为引用 DB-Library 的项目尝试了 NuGet...编辑了 web.config、App.config、whatever.config。还是一样的错误
更新:
这是在 VS2013 中创建的全新 project/solution。因此,我没有升级问题或其他问题。只是一个干净的新解决方案...
您的前端配置文件必须像这样注册提供商:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices,
EntityFramework.SqlServer" />
</providers>
</entityFramework>
在您通过 nuget 添加 Entity Framework 6 后,应用程序配置应该已被修改(它还应该添加对程序集 EntityFramework.dll 和 EntityFramework.SqlServer.dll 的引用),
您可以通过在程序包管理器控制台中发出 "Install-Package EntityFramework -Version 6.0.0" 来做到这一点。
(注意有较新的版本,请参阅 https://www.nuget.org/packages/EntityFramework)。
之后,您只需重建解决方案(这样应用程序配置就会被复制到项目的输出文件夹中,EDMX 设计人员会在其中查找它)。
您的项目还需要以 .NET 4 或 .NET 4.5 为目标才能使用 EF6。
我当前的设置:
VS1013-解决方案
- MvcProject (MVC5)
- FrameworkProject (ClassLibrary) - BaseController、BaseViewModel 等
- EntitiesProject (ClassLibrary) - edmx 仅作为 .cs 文件
- EntitiesProjectIO (ClassLibrary) - InBetweenLayer 以获取基础数据库中的get/set数据
我在 'MvcProject' 中添加了对 'EntitiesProjectIO' 的引用,并调用了 'GetData(...)'。
Schema specified is not valid. Errors: \r\nSurgeryManagementEntities.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
是我收到的消息,我现在知道 *** 是怎么回事了。 我已经添加了对几乎每个已知程序集的引用,并从纯数据库项目 (EntitiesProject) 复制了文件。 还复制了 EntityFramework.dll,为引用 DB-Library 的项目尝试了 NuGet...编辑了 web.config、App.config、whatever.config。还是一样的错误
更新:
这是在 VS2013 中创建的全新 project/solution。因此,我没有升级问题或其他问题。只是一个干净的新解决方案...
您的前端配置文件必须像这样注册提供商:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices,
EntityFramework.SqlServer" />
</providers>
</entityFramework>
在您通过 nuget 添加 Entity Framework 6 后,应用程序配置应该已被修改(它还应该添加对程序集 EntityFramework.dll 和 EntityFramework.SqlServer.dll 的引用), 您可以通过在程序包管理器控制台中发出 "Install-Package EntityFramework -Version 6.0.0" 来做到这一点。 (注意有较新的版本,请参阅 https://www.nuget.org/packages/EntityFramework)。
之后,您只需重建解决方案(这样应用程序配置就会被复制到项目的输出文件夹中,EDMX 设计人员会在其中查找它)。
您的项目还需要以 .NET 4 或 .NET 4.5 为目标才能使用 EF6。