找不到System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer

Vin*_*zon 21 c# entity-framework-6

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

实体框架提供程序类型"System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer,版本= 6.0.0.0,文化=中性公钥= b77a5c561934e089"为"System.Data.SqlClient的" ADO.NET提供者不能加载.

我正在使用6.0.0-alpha2-11210.

我发现这很奇怪,因为我有一个对Entity.SqlServer的引用,并且我设法通过在查询之前放入以下代码行来"修复它":

var patch_only = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
Run Code Online (Sandbox Code Playgroud)

这是alpha版本的bug吗?

Fab*_*ice 38

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

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

Type _Hack = typeof(System.Data.Entity.SqlServer.SqlProviderServices)
Run Code Online (Sandbox Code Playgroud)


Bre*_*ogt 13

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

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

MyProject.Infrastructure.EntityFramework
MyProject.Web
Run Code Online (Sandbox Code Playgroud)

在第一个项目中,我将设置所有的存储库DbContext,等等.在这个项目中,我有2个参考:

EntityFramework
EntityFramework.SqlServer
Run Code Online (Sandbox Code Playgroud)

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

private readonly IMyRepository myRepository;

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

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

     return View();
}
Run Code Online (Sandbox Code Playgroud)

这是我遇到问题的地方,打电话FindById.

我所做的只是将以下参考添加到我的网站:

EntityFramework.SqlServer
Run Code Online (Sandbox Code Playgroud)

在我的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>
Run Code Online (Sandbox Code Playgroud)

在结束system.webServer标记下面:

<entityFramework>
     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
               <parameter value="v11.0" />
          </parameters>
     </defaultConnectionFactory>
</entityFramework>
Run Code Online (Sandbox Code Playgroud)

我希望这将有所帮助.

  • 这不是为什么需要此引用或是否是错误的答案.所描述的解决方法是显而易见的,因此没有用处. (2认同)

小智 10

问题是"EntityFramework.SqlServer"引用.

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

所以,我通过将该引用添加到客户端来解决了这个问题.