首页 文章

实体框架提供程序错误

提问于
浏览
1

大家好我很喜欢连接到sql数据库服务器 . 我正在使用Entity framework v6并首次尝试代码第一种方法 . 下面我将向您展示我的 app.config 文件和错误消息我得到了我检查出类似的问题,大多数答案都是关于缺失 EntityFramework.SqlServer.dll 我有这个dll引用

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="HotelDB"
         connectionString="Data Source=(localdb)\v11.0;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/>
  </connectionStrings>
</configuration>

错误信息:

System.InvalidOperationException:找不到具有不变名称“System.Data.SqlClient”的ADO.NET提供程序的实体框架提供程序 . 确保提供程序已在应用程序配置文件的“entityFramework”部分中注册 . 有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882 .

3 回答

  • 3

    你找到了解决这个问题的方法吗?否则你可以看看这里:Entity Framework Provider type could not be loaded?

    大多数情况下,当我看到此异常时,它已安装实体框架(和/或缺少 EntityFramework.SqlServer.dll ) .

    举个例子,如果解决方案中有2个项目:

    • WebApp

    • DataAccess

    并在DataAccess项目中安装了Entity Framework . 当想要从WebApp中的DataAccess项目调用类(例如存储库)上的方法时,需要做两件事:

    • WebApp需要对DataAccess的引用

    • Webapp还需要安装EF

    当DataAccess安装了EF并随后添加为WebApp的引用时,WebApp项目(通常)也将安装EF . 有时在意外情况下,WebApp中的EF安装失败 . 因此,不添加所需的引用并显示您提到的异常消息 . 希望这个答案能够帮助其他人 .

  • 1

    我也有类似的问题

    通过执行以下操作解决了我的问题:

    enter image description here

    enter image description here

  • 0

    如果解决方案没有任何效果,那么请检查WebApp的packages.config和Entity Framework版本的DataAccess . 如果您在WebApp的packages.config文件中看到或看不到EF的条目,请转到引用并从WebApp中删除EF并使用程序包管理器控制台再次安装它,并提供以下命令:

    Install-Package“EntityFramework”-Version(版本号)其中版本号是DataAccess的packages.config中存在的版本 . 示例:Install-Package“EntityFramework”-Version“6.1.3”

相关问题