如何解决 Entity Framework 提供商异常
How do I solve The Entity Framework provider exception
我已将我的 WCF 项目发布到服务器上,我还将 MVC 应用程序发布到使用 WCF 服务的同一个盒子上。
尝试登录我的 MVC 应用程序时,这使用了 wcf 服务,但我在浏览器上遇到了这个异常,
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.
这是一个 entity framework 异常,但我假设因为我的项目已经在开发环境中引用了 EF,所以在部署服务项目之后,DLL 也应该包含 EF 引用,但我不确定为什么我收到这个错误。
我能看到这条消息是因为我打开了 includeExceptionDetailInFaults="True"
@FranciscoGoldenstein 说!您不需要在您的控制台应用程序或其他任何地方安装 Entity Framework,您只需要添加对程序集 EntityFramework.SqlServer.dll 的引用。您可以将此程序集从使用 Entity Framework 的 Class 库项目复制到 LIB 文件夹并添加对它的引用。
总结:
- Class图书馆申请:
- 安装Entity Framework
- 编写您的数据层代码
- app.config 文件包含与 Entity Framework 相关的所有配置,但连接字符串除外。
- 创建控制台、Web 或桌面应用程序:
- 添加对第一个项目的引用。
- 添加对 EntityFramework.SqlServer.dll 的引用。
- app.config/web.config 具有连接字符串(请记住,配置条目的名称必须与 DbContext class 的名称相同。
它适合我!希望对你有帮助。
也试试这个linkEntity Framework Provider type could not be loaded?
卸载 Entity Framework nuget 并重新安装,对我有用。
我也遇到了类似的问题
我的问题已通过执行以下操作解决:
解决此问题的最简单方法是在 EF 项目的 类 之一中添加以下行:
public class Blablabla
{
private static string __hack = typeof(SqlProviderServices).ToString();
// other class members as they were before.
}
这将强制构建过程将 EntityFramework.SqlServer.dll 复制到引用 EF 项目的任何项目的 \bin
文件夹。
无需安装 EF nuget 包或在任何下游项目中显式引用 EntityFramework.SqlServer.dll。
也许有些愚蠢,但供将来参考:
就我而言,我使用的是单元测试。我将配置添加到 app.config,但从未将 Entity Framework 安装到单元测试项目。
安装后,一切顺利。
我已将我的 WCF 项目发布到服务器上,我还将 MVC 应用程序发布到使用 WCF 服务的同一个盒子上。
尝试登录我的 MVC 应用程序时,这使用了 wcf 服务,但我在浏览器上遇到了这个异常,
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.
这是一个 entity framework 异常,但我假设因为我的项目已经在开发环境中引用了 EF,所以在部署服务项目之后,DLL 也应该包含 EF 引用,但我不确定为什么我收到这个错误。
我能看到这条消息是因为我打开了 includeExceptionDetailInFaults="True"
@FranciscoGoldenstein 说!您不需要在您的控制台应用程序或其他任何地方安装 Entity Framework,您只需要添加对程序集 EntityFramework.SqlServer.dll 的引用。您可以将此程序集从使用 Entity Framework 的 Class 库项目复制到 LIB 文件夹并添加对它的引用。
总结:
- Class图书馆申请:
- 安装Entity Framework
- 编写您的数据层代码
- app.config 文件包含与 Entity Framework 相关的所有配置,但连接字符串除外。
- 创建控制台、Web 或桌面应用程序:
- 添加对第一个项目的引用。
- 添加对 EntityFramework.SqlServer.dll 的引用。
- app.config/web.config 具有连接字符串(请记住,配置条目的名称必须与 DbContext class 的名称相同。
它适合我!希望对你有帮助。
也试试这个linkEntity Framework Provider type could not be loaded?
卸载 Entity Framework nuget 并重新安装,对我有用。
我也遇到了类似的问题
我的问题已通过执行以下操作解决:
解决此问题的最简单方法是在 EF 项目的 类 之一中添加以下行:
public class Blablabla
{
private static string __hack = typeof(SqlProviderServices).ToString();
// other class members as they were before.
}
这将强制构建过程将 EntityFramework.SqlServer.dll 复制到引用 EF 项目的任何项目的 \bin
文件夹。
无需安装 EF nuget 包或在任何下游项目中显式引用 EntityFramework.SqlServer.dll。
也许有些愚蠢,但供将来参考:
就我而言,我使用的是单元测试。我将配置添加到 app.config,但从未将 Entity Framework 安装到单元测试项目。
安装后,一切顺利。