C# 找不到 System.Data.Entity.SqlServer.SqlProviderServices、EntityFramework.SqlServer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14695163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 12:42:22  来源:igfitidea点击:

Can't find System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer

c#entity-framework-6

提问by Vincent-Philippe Lauzon

I'm constructing a DbContext from an SqlConnection. When I use it, I receive the following error:

我正在从 SqlConnection 构建一个 DbContext。当我使用它时,我收到以下错误:

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.

“System.Data.SqlClient”ADO.NET 提供程序的实体框架提供程序类型“System.Data.Entity.SqlServer.SqlProviderServices、EntityFramework.SqlServer、Version=6.0.0.0、Culture=neutral、PublicKeyToken=b77a5c561934e089”不能是加载。

I'm using 6.0.0-alpha2-11210.

我正在使用 6.0.0-alpha2-11210。

I found that weird since I have a reference toward Entity.SqlServer and that I managed to 'fix it' by putting the following line of code before a query:

我发现这很奇怪,因为我引用了 Entity.SqlServer 并且我设法通过在查询之前放置以下代码行来“修复它”:

var patch_only = System.Data.Entity.SqlServer.SqlProviderServices.Instance;

Is it a bug of the alpha version?

这是alpha版本的错误吗?

采纳答案by Brendan Vogt

I hope I am not late. I am using ASP.NET MVC4 and Entity Framework 6 alpha 3and ran into a similar problem.

我希望我没有迟到。我正在使用ASP.NET MVC4 并且Entity Framework 6 alpha 3遇到了类似的问题。

I have multiple projects in my solution. The 2 main projects are:

我的解决方案中有多个项目。2个主要项目是:

MyProject.Infrastructure.EntityFramework
MyProject.Web

In the first project I would set up all my repositories, DbContext, etc etc. In this project I have 2 references:

在第一个项目中,我会设置我所有的存储库DbContext,等等。在这个项目中,我有 2 个引用:

EntityFramework
EntityFramework.SqlServer

The second project is my website. It uses the repositories in the first project to return my data. For example:

第二个项目是我的网站。它使用第一个项目中的存储库来返回我的数据。例如:

private readonly IMyRepository myRepository;

public MyController(IMyRepository myRepository)
{
     this.myRepository = myRepository;
}

public ActionResult Details(int id)
{
     MyObject myObject = myRepository.FindById(id);

     return View();
}

This is where I had my issues, calling FindById.

这是我遇到问题的地方,调用FindById.

All that I did was to add the following reference to my website:

我所做的只是在我的网站上添加以下引用:

EntityFramework.SqlServer

In my web.config:

在我的 web.config 中:

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

And beneath the closing system.webServertag:

在结束system.webServer标签下方:

<entityFramework>
     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
               <parameter value="v11.0" />
          </parameters>
     </defaultConnectionFactory>
</entityFramework>

I hope this will help.

我希望这将有所帮助。

回答by Fabrice

What you did creates a reference to EntityFramework.SqlServer.dll. It ensures that this assembly gets copied over to the bin folder of projects using you data access assembly.

您所做的创建了对 EntityFramework.SqlServer.dll 的引用。它确保使用您的数据访问程序集将此程序集复制到项目的 bin 文件夹中。

You can do the same by adding something like the following somewhere in your data access assembly:

您可以通过在数据访问程序集中的某处添加类似以下内容来执行相同的操作:

Type _Hack = typeof(System.Data.Entity.SqlServer.SqlProviderServices)

回答by Tobias Koller

@LeLong37

@LeLong37

I had exactly the same error like you: "... No Entity Framework provider found for 'System.Data.SqlServerCe.4.0' ADO.NET provider..."

我有和你一样的错误:“......没有为'System.Data.SqlServerCe.4.0'ADO.NET提供程序找到实体框架提供程序......”

I solved it by adding a reference to "EntityFramework.SqlServerCompact" from directory "packages\EntityFramework.SqlServerCompact.6.0.0-rc1\lib\net40"

我通过从目录“packages\EntityFramework.SqlServerCompact.6.0.0-rc1\lib\net40”中添加对“EntityFramework.SqlServerCompact”的引用来解决它

hope this helps

希望这可以帮助

回答by Eren

The problem is the "EntityFramework.SqlServer" reference.

问题是“EntityFramework.SqlServer”引用。

In my project, when I added Entity Framework 6.0.1 by using NuGet in data access layer, I got the same error in the client side since client side doesn't have that reference.

在我的项目中,当我通过在数据访问层中使用 NuGet 添加 Entity Framework 6.0.1 时,我在客户端遇到了相同的错误,因为客户端没有该引用。

So, I solved the issue by adding that reference into the client side, too.

因此,我也通过将该引用添加到客户端来解决该问题。

回答by Karl

I am using EF 4 and EF 6 two different projects in the same solution.

我在同一个解决方案中使用 EF 4 和 EF 6 两个不同的项目。

After using NuGet for EF 6.0 all references to EF 4 where removed in my test Project. I had to remove EF6 from the project again and added references to System.Data.Entity for EF4.

将 NuGet 用于 EF 6.0 后,所有对 EF 4 的引用都已在我的测试项目中删除。我不得不再次从项目中删除 EF6,并为 EF4 添加了对 System.Data.Entity 的引用。

To access data thru EF6 in the test Project I had to manually reference the EntityFramework.SqlServer.dll (4.5) and used the hack (above) recommendation.

要在测试项目中通过 EF6 访问数据,我必须手动引用 EntityFramework.SqlServer.dll (4.5) 并使用 hack(以上)建议。

There was no need to do any alternations in the app.config of my test project.

无需在我的测试项目的 app.config 中进行任何更改。

no

 <section name="entityFramework" ...

and no

和不

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> ...

回答by Alexander Schmidt

I added a screencast at Youtubedescribing this and the solution in about 6 minutes. I did this because the solution provided by Fabrice is not working when you work with Team Build which runs into the same issue.

我在Youtube 上添加了一个截屏视频,在大约 6 分钟内描述了这个和解决方案。我这样做是因为当您使用遇到相同问题的 Team Build 时,Fabrice 提供的解决方案不起作用。

回答by MarkWalls

If you are having problems with a brand new MVC site from the template: 1) Uninstall Microsoft.ASPNet.Identity.EntityFramework (It will ask you if you want to uninstall Entity Framework - go ahead and do that.) 2) Install Entity Framework 3) Reinstall Microsoft.ASPNET.Identity.EntityFramework

如果您在使用模板中的全新 MVC 站点时遇到问题:1) 卸载 Microsoft.ASPNet.Identity.EntityFramework(它会询问您是否要卸载实体框架 - 继续执行此操作。)2)安装实体框架3) 重新安装 Microsoft.ASPNET.Identity.EntityFramework

Should be working now.

现在应该可以工作了。

回答by user5306225

I solved the problem by copying the two files

我通过复制两个文件解决了这个问题

EntityFramework.SqlServer.dll
EntityFramework.SqlServer.xml

to the /bin.

/bin.