【问题标题】:Referencing to the EntityFramework.dll cause an run-time error in VS2010在 VS2010 中引用 EntityFramework.dll 会导致运行时错误
【发布时间】:2013-11-27 14:31:01
【问题描述】:

[更新]

我的解决方案中有 2 个项目。第一个是我的 DAL 项目(类库),第二个是 Windows 项目(UI),我的 DAL 项目引用了 EF 4.3.1 并且工作正常, 最近我将我的 DAL 项目引用到 EF6,在 VS2010 中通过 Update-Package EntityFramework 命令使用包管理器控制台,在应用 EF official site 中的建议更改后,现在是 app.config我的 DAL 项目 包括以下几行:

<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">
  <parameters>
    <parameter value="Data Source=MyServer;Initial Catalog=erptest;Persist Security Info=True;User ID=sa_l4;password=12212121;application name = LEVEL4" />
  </parameters>
</defaultConnectionFactory>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>

但是当我运行我的项目时,当控制来到下面一行时

var context = new MyDbContext();

我收到了这个错误:

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.Odbc'. Make sure the provider is registered in the 'entityFramework' section of the application config file

有谁知道,问题出在哪里?

【问题讨论】:

    标签: c# visual-studio-2010 entity-framework ef-code-first runtime-error


    【解决方案1】:

    由于您的 DAL 项目是一个类库,因此它将使用使用它的应用程序的配置。

    尝试将 Entity Framework Nuget 包添加到您的 UI 项目中。它会将所需的设置添加到配置中。

    更新

    此问题也可能是由 Glimpse 或 EF Profiler 等分析工具引起的。如果您正在使用其中任何一个,请尝试禁用它们以查看是否可以解决问题。

    【讨论】:

    • 您是否在使用任何类型的分析器,例如 EF Profiler 或 Glimpse?似乎它们会导致 EF 出现问题 - stackoverflow.com/q/15857349/2868772
    • 非常感谢snacky,问题解决了,我使用了EF Profiler,当禁用它时,问题解决了。请更新您的帖子。你知道我还可以如何使用 EF 分析器吗?
    • 没问题,很高兴为您提供帮助。我已按要求更新了答案。它看起来像一个错误,所以你应该联系 Hibernating rhinos 支持 - hibernatingrhinos.com/contact
    • 我在安装 EF6 后得到了这个,删除 Glimpse 修复了它,谢谢snacky
    【解决方案2】:

    听起来像是配置问题...您的web.config 文件中有以下条目吗?

    <entity-framework>
        <providers>
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
    </entity-framework>
    

    您的特定配置条目可能需要一些额外/不同的条目/属性,但您可以在此处阅读有关 EF6 配置的更多信息:

    http://msdn.microsoft.com/en-us/data/jj556606.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-06
      • 2019-05-31
      • 2013-07-08
      • 2014-06-09
      • 2020-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多