gpt4 book ai didi

.net - 无法加载 Entity Framework 提供程序类型 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'

转载 作者:行者123 更新时间:2023-12-04 22:11:10 26 4
gpt4 key购买 nike

我使用dotNet 4.5创建了WCF服务。数据库层是使用Entity Framework 6构建的。

我使用IIS 8托管了该服务。它运行正常。

现在,我需要使用Windows窗体客户端使用该服务,该客户端是使用dotnet framework 3.5构建的。

我可以成功创建服务引用。但是,当我运行代码时,出现以下错误;

The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.



有什么建议么?

最佳答案

您不需要在客户端应用程序中安装EF6 NuGet Package,该错误与客户端应用程序无关,因为客户端应用程序连接到WCF服务,并且即使存在数据库或数据访问层也不知道。

此错误与服务库和/或宿主项目的bin文件夹中缺少EntityFramework.SqlServer.dll有关。

选项1

最简单的方法是在WCF Host项目中也使用NuGet软件包管理器安装EF6,如果以前已安装过,请尝试再次卸载并安装。这种方式EntityFramework.SqlServer.dll输出目录。

请注意,这种方式在某种程度上违反了n层规则,因为您数据访问层以上的库依赖于EF6,效果不是很好。

选项2

作为一种在输出目录中复制EntityFramework.SqlServer.dll的解决方法,请确保将此dll的Copy Local设置为true,然后将此代码放入 DbContext 构造函数中:

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

它确保将 EntityFramework.SqlServer.dll复制到数据访问项目使用者的输出目录中。这是一种解决方法。

使用这种方法,您在数据访问层上方的层中就不会依赖EF。

关于.net - 无法加载 Entity Framework 提供程序类型 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32607736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com