[更新]
我的解决方案中有2个项目。第一个是我的DAL项目(类库),第二个是Windows项目(UI),我的DAL项目引用了EF 4.3.1并正常工作,
在EF official site中应用建议的更改之后,最近我在VS2010中使用程序包管理器控制台EF6
引用了我的DAL项目到Update-Package EntityFramework
,现在是我的DAL项目的 app.config 包括以下几行:
<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
有谁知道,问题出在哪里?
答案 0 :(得分:4)
由于您的DAL项目是类库,它将使用消耗它的应用程序的配置。
尝试将Entity Framework Nuget包添加到UI项目中。它会将所需的设置添加到配置中。
<强>更新强>
此问题也可能由Glimpse或EF Profiler等分析工具引起。如果您使用其中任何一种,请尝试禁用它们以查看它是否能解决问题。
答案 1 :(得分:1)
听起来像配置问题...您的web.config
文件中是否有以下条目?
<entity-framework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entity-framework>
您的特定配置条目可能需要一些额外/不同的条目/属性,但您可以在此处阅读有关EF6配置的更多信息: