引用到EntityFramework.dll会导致VS2010中的运行时错误 [英] Referencing to the EntityFramework.dll cause an run-time error in VS2010

查看:182
本文介绍了引用到EntityFramework.dll会导致VS2010中的运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[已更新]

我的解决方案中有2个项目。第一个是我的DAL项目(Class Library),第二个是Windows Project(UI),我的DAL Project参考了EF 4.3.1,并且正常工作,
最近,我引用了我的DAL项目到 EF6 ,使用软件包管理器控制台,通过 Update-Package EntityFramework 命令,在VS2010中应用推荐更改 EF官方网站,现在我的DAL项目的app.config 包括以下行:

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>

<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();

我收到此错误:

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?

推荐答案

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

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

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

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

更新

此问题也可以由像Glimpse或EF Profiler这样的分析工具引起。如果您正在使用它们,请尝试禁用它们,看是否可以解决问题。

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.

这篇关于引用到EntityFramework.dll会导致VS2010中的运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆