【问题标题】:Entity Framework Provider type could not be loaded?无法加载实体框架提供程序类型?
【发布时间】:2012-12-11 13:48:12
【问题描述】:

我正在尝试在我的机器上当前安装的 TeamCity 上运行测试。

System.InvalidOperationException

实体框架提供程序类型 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 对于'System.Data.SqlClient' 无法加载 ADO.NET 提供程序。确保提供程序程序集 可用于正在运行的应用程序。

请参阅http://go.microsoft.com/fwlink/?LinkId=260882 了解更多信息 信息..

我的任何项目中都没有提到 System.Data.Entity,正如 codeplex 上建议的升级到 EF6。

所以,我不确定为什么会出现此异常。 当我从 VS 运行测试时,我没有遇到任何此类异常。

我确实尝试将 CopyLocal 设置为 false,然后再次设置为 true.. 但这似乎也不起作用。

更新

我的 app.config 有以下内容。这会导致一些我不理解的行为吗?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

我在 teamcity 中得到以下堆栈跟踪。

[MSTest] IntegrationTests.CrudTest+QuestionTest.Create
[03:59:11][IntegrationTests.CrudTest+QuestionTest.Create] Initialization method IntegrationTests.CrudTest+QuestionTest.Initialize threw exception. System.InvalidOperationException: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' ADO.NET provider could not be loaded. Make sure the provider assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information..
[03:59:11]
[IntegrationTests.CrudTest+QuestionTest.Create]     at System.Data.Entity.Config.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName)
   at System.Data.Entity.Config.ProviderServicesFactory.GetInstanceByConvention(String providerInvariantName)
   at System.Data.Entity.Config.DefaultProviderServicesResolver.GetService(Type type, Object key)
   at System.Data.Entity.Config.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at System.Data.Entity.Config.CachingDependencyResolver.GetService(Type type, Object key)
   at System.Data.Entity.Config.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Data.Entity.Config.ResolverChain.GetService(Type type, Object key)
   at System.Data.Entity.Config.RootDependencyResolver.GetService(Type type, Object key)
   at System.Data.Entity.Config.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Data.Entity.Config.ResolverChain.GetService(Type type, Object key)
   at System.Data.Entity.Config.CompositeResolver`2.GetService(Type type, Object key)
   at System.Data.Entity.Config.IDbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
   at System.Data.Entity.Config.InternalConfiguration.GetService[TService](Object key)
   at System.Data.Entity.Config.DbConfiguration.GetService[TService](Object key)
   at System.Data.Entity.Utilities.DbProviderFactoryExtensions.GetProviderServices(DbProviderFactory factory)
   at System.Data.Entity.Infrastructure.DefaultManifestTokenService.GetProviderManifestToken(DbConnection connection)
   at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
   at System.Data.Entity.DbSet`1.Add(TEntity entity)
   at EFRepository.Infrastructure.EFRepository`1.Add(T item) in c:\TeamCity\buildAgent\work\da2ea4e72c0e77f0\Repository\Infrastructure\EFRepository.cs:line 22
   at IntegrationTests.CrudTest.Initialize() in c:\TeamCity\buildAgent\work\da2ea4e72c0e77f0\IntegrationTests\CrudTest.cs:line 34

【问题讨论】:

  • EntityFramework.SqlServer.dll 是否与 EntityFramework.dll 一起部署?在 EF6 中,SqlServer 和 SqlServerCE 提供程序与之前版本的 EF 引擎不在同一个程序集中。您不应添加对 System.Data.Entity.dll 的引用。与 EF5 相比,EF6 中的提供程序模型发生了变化,而 EF5 提供程序将无法正常工作。此外,您可能会遇到一些棘手的问题(例如 EF5 地理空间类型在 EF6 中被视为实体类型)
  • 是的,我仔细检查了没有对 System.Data.Entity 的引用,并且对 EntityFramework.dll 和 EntityFramework.SqlServer.dll 的引用都存在。 projetc 再次编译并在 VS 中运行测试。只有当我在 TeamCity 上运行测试时才会出现错误。
  • 这是一个正确的设置。我没有使用 TeamCity,但在我看来,当您的应用程序被部署以使用 TeamCity 运行测试时,EntityFramework.SqlServer.dll 丢失,因此出现异常。
  • 查看这篇文章的答案:stackoverflow.com/questions/21175713/… 我添加了private volatile Type _dependency... 答案,它成功了!只是为了让 EF 在 TeamCity 中工作,我必须添加一个像这样的单独类。
  • 我从 nuget 包中卸载了 EntityFramework 并再次安装,它得到了修复

标签: c# entity-framework mstest teamcity-7.1 entity-framework-6


【解决方案1】:

同样的问题,但我通过 Nuget 安装了 EF 6。另一个可执行文件缺少 EntityFramework.SqlServer。我只是将 nuget 包添加到该项目中。

【讨论】:

  • 我也注意到了这一点。如果您创建一个使用 EF 的库,VS 会将 EF.dll 和 EF.SqlServer.dll 放入该构建文件夹中。但是,如果您现在有另一个程序使用您的库,则只有 EF.dll 将被放入此构建文件夹中。 EF.SqlServer.dll 丢失。如果您手动将其添加到构建文件夹,则该程序可以运行。本身不是一个很好的解决方案,但表明问题是缺少 EF.SQLServer.dll 是错误的原因。
  • 我添加了 var x = typeof(System.Data.Entity.SqlServer.SqlProviderServices);然后我的应用程序工作了
  • 当我输入代码时,我总是担心什么都不做,突然我的项目运行了。 O_o
  • 另外,由于编译器优化,您可能还想执行x.ToString(),否则它将在Release 中删除typeofs。
  • 我发现 EF 6.1 现在需要在我的 ASPX DLL/项目上安装 EF 很烦人,而 EF 5.0 只需要在我的数据层 DLL/项目上安装它。
【解决方案2】:

我在我的测试项目中遇到了同样的问题 - 我通过 NuGet 安装了最新的 EF6 位,并且每次我调用与 EF 相关的东西时都会得到:

实体框架提供程序类型 'System.Data.Entity.SqlServer.SqlProviderServices, 'System.Data.SqlClient' ADO.NET 的 EntityFramework.SqlServer' 无法加载提供程序。确保提供程序程序集是 可用于正在运行的应用程序。看 http://go.microsoft.com/fwlink/?LinkId=260882 了解更多信息。

我的解决方法:我将此方法放在我的测试项目中:

public void FixEfProviderServicesProblem()
{
//The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'
//for the 'System.Data.SqlClient' ADO.NET provider could not be loaded. 
//Make sure the provider assembly is available to the running application. 
//See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}

从未调用过此方法,但我认为编译器将删除所有“不必要的”程序集,并且在不使用 EntityFramework.SqlServer 的情况下测试失败。

无论如何:在我的机器上工作;)

注意:Instead of adding the method to test project you can ensure a static reference to SqlProviderServices from your Model/entity project.

【讨论】:

  • 我最终也做了同样的事情。我想和那个使这个程序集依赖于打开与 db 的连接的人交谈。在他们的备用宇宙中,我们所有具有带有连接字符串的配置文件的前端项目都应该引用 EntityFramework 只是为了让这个 dll 打开连接。这有什么意义我不明白。
  • 这是一个 hack,但对于您没有为您的项目创建部署包的场景,这是我发现的最好/最简单的解决方案。
  • 对于使用“var x = typeof(SqlProviderServices);”等其他建议的所有人。只有罗伯特提供的这个解决方案才能用于开发和构建机器!!!
  • 谢谢罗伯特,EF 团队觉得这很荒谬,但无论如何这对我有用。
  • 要明确:将上述代码添加到您的 DbContext 类将解决 EF 6.1 中的问题。这样您就不需要在前端(WebApi 等)项目中包含 Entity Framework Nuget 包,并且可以将所有与 EF 相关的内容留在数据层中。
【解决方案3】:

Nuget 会将您的 EF6 项目配置为引用 EntityFramework.SqlServer.dll。这会在构建期间部署到 EF6 项目的输出文件夹,但不会部署到引用 EF6 项目的项目的输出文件夹。我相信这是因为 Visual Studio 足够“智能”,可以检测到您的程序集中没有任何东西实际上是直接使用 dll,因此不包含它。您可以通过将代码添加到使用 EntityFramework.SqlServer.dll 的 EF6 项目来强制将 EntityFramework.SqlServer.dll 部署到引用您的 EF6 项目(单元测试、UI 等)的项目的输出文件夹。请注意不要将代码放在生成的类中,因为您可能会在下一次重新生成时丢失它。我选择将以下类添加到程序集中,从而解决了问题。

using System.Data.Entity.SqlServer;

internal static class MissingDllHack
{
    // Must reference a type in EntityFramework.SqlServer.dll so that this dll will be
    // included in the output folder of referencing projects without requiring a direct 
    // dependency on Entity Framework. See http://stackoverflow.com/a/22315164/1141360.
    private static SqlProviderServices instance = SqlProviderServices.Instance;
}

【讨论】:

  • 这为我解决了关于 MSTest 的问题。我喜欢这种方法,因为它不需要我对测试类的类继承做任何混乱的事情。只需在测试程序集和 MAGIC 中的某处包含该类。谢谢!
  • 没错,这就是它没有将 sqlserver.dll 复制到引用项目输出的原因。当您在执行应用程序和上下文程序集之间多了一层时,就会发生这种情况。谢谢这解决了我的问题。
  • 对于那些不想花 4 秒钟查找它的人:使用 System.Data.Entity.SqlServer;
  • 我们使用一个通用的单元测试基类,所有的单元测试都继承自这个类。将此方法添加到该类意味着所有具有从基类继承的单元测试类的项目都可以正常工作。
  • 小意思,但最好在这个类中添加注释来解释为什么它是必要的。
【解决方案4】:

我的解决方案是通过 nuget 管理器从项目中删除实体框架,然后重新添加。

【讨论】:

  • PM&gt; Update-Package -Reinstall "EntityFramework" -ProjectName "MyProj1"
  • 这对我来说很有效,我认为这可能是最佳解决方案
  • 简单、干净的解决方案。应该在列表上更高
  • 这里也一样。谢谢!感谢@VahidN 的命令。
【解决方案5】:

我通过在我的 DBContext 类顶部添加一个 using 语句解决了这个问题,如下所示:

using SqlProviderServices= System.Data.Entity.SqlServer.SqlProviderServices;

【讨论】:

  • 这是解决这个问题的最干净的方法。谢谢。
  • 这个解决方案有效并且看起来很干净。问题:我们不会松开 DBContext 类刷新的行 id 吗?即使用 edmx 类生成?
  • 不敢相信这是必要的,而且微软没有以某种方式纠正 - 但这对我有用。感谢您提供简单的解决方案。
  • 此解决方案在功能上与MissingDllHack 相同。它可能看起来更干净,但在您的上下文类中引入了解决方法代码。此代码也将被 ReSharper 等工具标记为删除,并且随着时间的推移很容易丢失。一个很好的解决方案,但我更喜欢以一种不会产生代码警告的方式将解决方法与上下文分开。
【解决方案6】:

我使用了基于代码的注册提供商。 link1 link2

刚刚创建了类似的配置类

class DbContextConfiguration : DbConfiguration
{
    public DbContextConfiguration()
    {
        this.SetDatabaseInitializer(new DropCreateDatabaseAlways<MyDbContext>());
        this.SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);
    }
}

重点是this.SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);

并以这种方式使用它

[DbConfigurationType(typeof(DbContextConfiguration))]
public class MyDbContext : DbContext
{
    public MyDbContext()
    {
        ...
    }

    public DbSet<...> ...{ get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        ...
    }
}

【讨论】:

  • 我在一个解决方案中有两个项目。第一个是具有实体框架程序集、DbContext 类和 tt 文件的类库。第二个项目是windows forms,应该使用ef-project获取数据。 @Nash:您能否详细说明您将班级DbContextConfiguration 放在哪里(进入哪个项目)?谢谢
  • 如上所述,附加引用似乎是解决此问题的一种方法(请参阅 eri​​c 的评论)。我使用了 nuget 控制台并触发了这个命令:Get-Project MyWinformsProject | Install-Package EntityFramework 它为我修复了它。我仍然想更好地理解原因。
  • DbContextConfiguration 似乎已经存在(与 2013 年相比),在 MyDbContext 类上方添加 DbConfiguraton 行并没有解决我的问题。
  • 您不需要 DbConfiguration 类。在应用启动时(使用 EF 之前)放置以下代码:DbConfiguration.Loaded += (sender, e) =&gt; e.ReplaceService&lt;DbProviderServices&gt;((s, k) =&gt; System.Data.Entity.SqlServer.SqlProviderServices.Instance);.
【解决方案7】:

我在我的程序集初始化类中使用 [DeploymentItem] 对其进行了整理

namespace MyTests
{
    /// <summary>
    /// Summary description for AssemblyTestInit
    /// </summary>
    [TestClass]
    [DeploymentItem("EntityFramework.SqlServer.dll")]
    public class AssemblyTestInit
    {
        public AssemblyTestInit()
        {
        }

        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [AssemblyInitialize()]
        public static void DbContextInitialize(TestContext testContext)
        {
            Database.SetInitializer<TestContext>(new TestContextInitializer());
        }
    }
}

【讨论】:

    【解决方案8】:

    我有问题,因为我没有添加对 EntityFramework.sqlServer.dll 的引用。 当我开发程​​序时,它可以工作。但是当我发布应用并安装它时,它会抛出错误。

    我只是添加参考并再次构建和发布。

    【讨论】:

    • 我做了这个,效果很好。基本上,当未正确引用库的组件时,项目将显示警告。
    【解决方案9】:

    聚会迟到了,但投票率最高的答案对我来说似乎都是 hack。

    我所做的只是从测试项目的 app.config 中删除以下内容。工作。

      <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>
    

    【讨论】:

    • 真正的解决方案!
    【解决方案10】:

    我已通过手动将EntityFramework.SqlServer.dll 文件复制到主应用程序的bin folder 来解决此问题。

    【讨论】:

      【解决方案11】:

      我看到类似的问题,并使用这篇文章中的方法:(http://entityframework.codeplex.com/workitem/1590),它解决了我的问题。

      要解决此问题,您可以通过在测试程序集的任何位置添加类似这样的行来使您的测试程序集直接引用提供程序程序集: var _ = System.Data.Entity.SqlServer.SqlProviderServices.Instance;

      【讨论】:

        【解决方案12】:

        我有同样的问题我尝试了很多次但它没有解决但是当我安装包 EntityFramework.SqlServerCompact 它解决了从 Nuget 包管理器安装这个包。

        Install-Package EntityFramework.SqlServerCompact
        

        【讨论】:

          【解决方案13】:

          我创建了一个静态“启动”文件并添加了代码以强制将 DLL 复制到其中的 bin 文件夹中,以此作为分隔此“配置”的一种方式。


          [DbConfigurationType(typeof(DbContextConfiguration))] public static class Startup { }

          public class DbContextConfiguration : DbConfiguration
          {
              public DbContextConfiguration()
              {
                  // This is needed to force the EntityFramework.SqlServer DLL to be copied to the bin folder
                  SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);
              }
          }
          

          【讨论】:

          • 谢谢!这是一个巨大的帮助。
          • 很高兴您发现我的回答很有帮助@AddisonSchuhardt :)
          • 这是一个巨大的帮助...对于仍在使用多个 EF 6 上下文的任何人的专业提示,您可能需要在项目中添加对 EntityFramework.SqlServer.dll 的手动引用并将此类​​添加到节点&lt;entityFramework codeConfigurationType="........"&gt;example&lt;/entityFramework&gt;中的配置文件。
          【解决方案14】:

          我终于解决了这个问题。事实证明,我的存储库类中有一个错误的 IDIsposable 实现。我修好了。 错误的实现导致了 stackoverflow 异常,因为我没有正确处理资源。这导致 VS 无法运行测试,测试执行引擎崩溃。

          我在这里向 Microsoft 提交了它(这是在我得到正确解决方案之前)。 connect.microsoft.com/VisualStudio/feedback/details/775868/vs-test-execution-crashes-in-vs-2012#details

          无论如何,现在构建在 teamcity 上运行良好。虽然,我仍然很好奇为什么 VS 测试执行引擎都没有优雅的方式告诉我发生了什么,而不是 Team City。

          我通过手动调试测试发现了根本原因(我花了这么多天才意识到,修复花了我 5 秒)。

          希望这对遇到此类问题的人有所帮助。

          【讨论】:

            【解决方案15】:

            当我检查问题时,我注意到输出文件夹中缺少以下 dll。如果应用程序处于调试模式,简单的解决方案是将 Entityframework.dll 和 Entityframework.sqlserver.dll 与 app.config 复制到输出文件夹。同时将app.config的构建选项参数“Copy to output folder”更改为始终复制。这将解决您的问题。

            【讨论】:

            • 我只为“EntityFramework.SqlServer”设置了“本地复制”为真。现在它可以工作了。
            【解决方案16】:

            只需引用或浏览 EF dll - EntityFramework.SqlServer.dll

            【讨论】:

            • 这就是我所做的。将“EntityFramework.SqlServer”的引用从我的库复制到“运行”项目。成功了!
            【解决方案17】:

            在尝试了所有其他建议的解决方案并且没有让我的项目运行之后,我终于在this page 中找到了一点评论:

            删除 BIN 文件夹对我有用

            它也对我有用。

            【讨论】:

            • 我正在合并 2 个分支 - 我的项目没有与 EF 相关的更改,但我的单元测试刚刚开始无缘无故地失败。删除 BIN 文件夹让他们再次工作。
            • @Zeek2 这个错误很棘手。在我引用的页面中有很多不同的建议可以解决这个问题。这只是众多可能的解决方案之一。继续研究它,直到找到适用于您的特定问题的解决方案,祝您好运。
            • 这也是我的解决方案真的很奇怪。
            【解决方案18】:

            我不想在我的应用程序项目中引用 EF(或手动复制任何内容),因此我将其添加到我的 EF 项目的构建后事件中:

            cp $(TargetDir)EntityFramework.SqlServer.dll $(SolutionDir){your-main-bin-folder}
            

            【讨论】:

              【解决方案19】:

              这只发生在我的负载/单元测试项目中。令人沮丧的是,我很高兴它出现在我已经运行了 2 年的项目中。一定是某种测试运行顺序破坏了事情。我想一旦那个fi被删除它就消失了。

              我发现只需声明一个使用正确值的变量就可以解决问题……我什至从不调用该方法。只需定义它。奇怪,但它有效。

                  /// <summary>
                  /// So that the test runner copies dlls not directly referenced by the integration project
                  /// </summary>
                  private void referenceLibs()
                  {
                      var useless = SqlProviderServices.Instance;
                  }
              

              【讨论】:

                【解决方案20】:

                我也有类似的问题

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

                【讨论】:

                  【解决方案21】:

                  我在从单元测试项目中实例化 DBContext 对象时遇到了同样的问题。我检查了我的单元测试项目包,发现 EntityFramework 包没有安装,我从 Nuget 安装它并解决了问题(我认为是 EF 错误)。

                  快乐编码

                  【讨论】:

                    【解决方案22】:

                    将 Entityframework.dll 和 Entityframework.sqlserver.dll 添加到参考项目中解决了这个问题。

                    【讨论】:

                    • 是的,当我的 packages.config 指向 6.1.3 时,我相信我的 csproj 文件以某种方式引用了 6.0.0(由于我移动了一些家具)
                    【解决方案23】:

                    我在单元测试项目中检查了调试输出窗口。 EntityFramework.SqlServer.dll 未加载。将其添加到 bin 文件夹后,测试运行成功。

                    【讨论】:

                      【解决方案24】:

                      我刚刚收到同样的错误消息。

                      我有一个单独的项目用于我的数据访问。在本地运行 Web 项目(它引用了数据项目)工作得很好。但是当我将 Web 项目部署到天蓝色的程序集时: EntityFramework.SqlServer 没有被复制。我刚刚添加了对 web 项目的引用并重新部署,现在它可以工作了。

                      希望这对其他人有所帮助

                      【讨论】:

                        【解决方案25】:

                        我正在离线学习 Contoso 大学教程,并在尝试使用 EF 创建我的第一个控制器时遇到了同样的问题。 我必须使用包管理器控制台从 nuget 缓存加载 EF 并创建一个连接到我的本地 SQL Server 实例的连接字符串,我的意思是我的 EF 的 webConfig 设置可能没有像你们一样设置,但我能够通过完全删除“entityFramework”中的“providers”部分来解决我的问题

                        罗伯特

                        【讨论】:

                          【解决方案26】:

                          有一个简单的解决方法。打开项目中的引用,右键单击“System.Data”-> 属性。将“复制本地”更改为“真”。

                          问题应该解决了。

                          【讨论】:

                            【解决方案27】:

                            在我之前安装 SQL Server Express 2012 (x64) 的情况下,我通过安装 SQL Server 2012 Developer Edition 解决了这个问题。这似乎为我提供了缺少的依赖项。

                            【讨论】:

                              【解决方案28】:

                              通过 nuget 从项目中删除实体框架,然后重新添加。

                              【讨论】:

                                【解决方案29】:

                                在我的情况下,dll 没有被复制,尽管我添加了对它的引用。这是因为EntityFramework.SqlServer.dll没有复制到您的项目中。添加该 dll,它有望工作。您可以从添加数据模型的项目中找到它。

                                【讨论】:

                                  【解决方案30】:

                                  除了此处所有有用的建议外,如果您使用的是 EF 6.1.3,请确保您的项目的 .net 版本为 4.5 或更高版本。

                                  【讨论】:

                                    猜你喜欢
                                    • 1970-01-01
                                    • 2015-12-12
                                    • 1970-01-01
                                    • 2017-04-26
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 1970-01-01
                                    相关资源
                                    最近更新 更多