我正在尝试通过以下项目建立一个简单的三层解决方案: - 客户端(WPF) - 服务(模型抽象层) - 模型(使用随 NuGet 安装的 Entity Framework )
我的期望是仅将模型和服务层引用到 Entity Framework 库,但在这种情况下,应用程序不会启动并显示错误消息:
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.
如“更多信息”主页上所述,我必须将实体提供程序配置添加到我的解决方案(客户端)的启动项目中。在这种情况下,“客户端”必须了解模型中使用的持久性技术。
是否有可能避免在“客户端”项目中引用 Entity Framework ?
最佳答案
不知道您是否已经找到解决这个问题的方法。但我遇到了这个问题并找到了解决方案,令人惊讶的是它有效。
在“xxx.Context.cs”
文件中,在主构造函数中添加以下代码:
public partial class MyOwnContext : DbContext
{
public MyOwnContext()
{
var _ = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
}
....
}
关于c# - .NET Entity Framework - 包结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20660339/