Referencing to the EntityFramework.dll cause an run-time error in VS2010

…衆ロ難τιáo~ 提交于 2019-12-12 00:28:21

问题


[Updated]

I have 2 projects in my solution. the first one is my DAL project(Class Library), and the second is a Windows Project(UI), my DAL Project referenced to EF 4.3.1 and worked normally, Recently I referenced my DAL project to EF6 , using Package Manager Console, by Update-Package EntityFramework command, in VS2010, after applying the recommended changes in EF official site, now the app.config of my DAL project include these lines:

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

and

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

But when I run my project, when control comes to below line

var context = new MyDbContext();

I got this error:

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

Does anyone knows, where is the problem?


回答1:


As your DAL project is a class library, it will use the config of the application which consumes it.

Try adding the Entity Framework Nuget package to your UI project. It will add the required settings to the config.

Update

This issue can also be caused by a profiling tools like Glimpse or EF Profiler. If you are using either, try disabling them to see if it will fix the problem.




回答2:


Sounds like a configuration issue...do you have the below entry in your web.config file?

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

Your specific config entries will likely need some additional/different entries/properties but you can read here for more info on EF6 configurations:

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



来源:https://stackoverflow.com/questions/20245124/referencing-to-the-entityframework-dll-cause-an-run-time-error-in-vs2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!