.NET实体框架 - 包结构

时间:2013-12-18 14:07:31

标签: c# .net entity-framework

我正在尝试使用以下项目设置一个简单的三层解决方案: - 客户(WPF) - 服务(模型抽象层) - 模型(使用与NuGet一起安装的实体框架)

我的期望是仅将模型和服务层引用到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.

如“更多信息”主页所述,我必须将实体提供程序配置添加到我的解决方案(客户端)的启动项目中。在这种情况下,“客户端”必须知道模型中使用的持久性技术。

是否有可能避免在“客户”项目中引用实体框架?

1 个答案:

答案 0 :(得分:4)

我不知道你是否已经找到了解决这个问题的方法。但是我遇到了这个问题并找到了解决方案,并且令人惊讶地确实有效。

"xxx.Context.cs"文件中,在主构造函数中添加以下代码:

public partial class MyOwnContext : DbContext
{
    public MyOwnContext()
    {
        var _ = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
    }
    ....
}