c# - MVC 5 项目中的 Entity Framework 6.0 不工作

标签 c# asp.net-mvc entity-framework entity-framework-6

我当前的设置:

VS1013-解决方案

  • Mvc项目(MVC5)
  • FrameworkProject (ClassLibrary) - BaseController、BaseViewModel 等。
  • EntitiesProject (ClassLibrary) - edmx 仅作为 .cs 文件
  • EntitiesProjectIO (ClassLibrary) - InBetweenLayer 获取底层数据库中的获取/设置数据

我在“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 中创建的全新项目/解决方案。因此,我没有升级问题或其他问题。只是一个干净的新解决方案...

最佳答案

您的前端配置文件必须像这样注册提供者:

<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 的引用), 您可以通过在包管理器控制台中发出“安装包 EntityFramework -Version 6.0.0”来做到这一点。 (注意有较新的版本,请参阅 https://www.nuget.org/packages/EntityFramework)。

之后,您只需要重建解决方案(这样应用程序配置就会被复制到项目的输出文件夹中,EDMX 设计人员会在其中查找它)。

您的项目还需要以 .NET 4 或 .NET 4.5 为目标才能使用 EF6。

关于c# - MVC 5 项目中的 Entity Framework 6.0 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28774658/

相关文章:

C# XmlReader 冒号问题(命名空间)

mysql - 对 mysql 数据库使用 asp.net mvc “membership” 抛出关键字不受支持。参数名称: attachdbfilename

mysql - 定义具有多对多关系的两个实体之间的关系

c# - 在 Asp.Net mvc 的 View 中渲染 View

c# - 简化 Linq 表达式

asp.net-mvc - EF6 Scaffolding/w FK to ApplicationUser 无法正确生成

c# - PCL 中的 Math.Round 函数

c# - 列表<类>() 与列表<类>(0)

c# - 如何通过 XAML 在 WPF 中将小写字母转换为大写字母?

asp.net-mvc - 仅在 mvc 6 中将值从 EditorTemplate 传递给其布局模板