我必须在所有项目中引用Entity

我必须在所有项目中引用Entity

本文介绍了我必须在所有项目中引用Entity Framework 6 dll吗? (不仅是我的DAL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

问题
-应用程序是否真的必须安装EF6才能使用另一个使用EF6作为其基础数据检索机制的类库(或者我误会了)?
-如何解决此问题并仍然使用EF?

Question
- Do applications really have to install EF6 to consume another class library that used EF6 as it's underlying data retrieval mechanism (or am I mistaken)?
- How can I work around this and still use EF?

场景
我们正在用新版本重写旧的DAL,该新版本使用EF6来获取其数据.消费者应用程序不调用EF上下文.相反,它们调用中间函数(在DAL项目的Business Logic文件夹中),从而依次调用EF.

Scenario
We are rewriting an old DAL with a new version that uses EF6 to get it's data. Consumer apps don't call on the EF context. They instead call intermediate functions (in a Business Logic folder in the DAL project), that in turn calls on EF.

当我有一个消耗性的应用程序引用我的新DAL(连接字符串和提供程序引用添加到它的.config中)时,编译器会抱怨缺少提供程序:

When I have a consuming app reference my new DAL (connection string and provider references added to it's .config), the compiler complains of a missing provider:

我可以通过将EF6软件包安装到正在使用的应用程序中来对此进行补救,但这是有问题的.我们有大量的消耗性应用程序,其中许多具有并行数据访问机制,这些机制通常包括较早版本的EF.我需要我的DAL独立于我的消费者.

I can remedy this by installing the EF6 package into my consuming application, but this is problematic. We have tons of consuming apps, many with parallel data access mechanisms that often include older versions of EF. I need my DAL to be independent from my consumers.

可以做到吗?

推荐答案

从EF4迁移到EF6时,我遇到了同样的问题.添加 EntityFramework.SqlServer.dll 作为对DAL库的引用,可以解决DAL连接问题,而不是消耗应用程序的问题.

I had the same issue when migrating from EF4 to EF6. Adding the EntityFramework.SqlServer.dll as a reference to your DAL library solves the problem for the DAL connection but not for the consuming apps.

之所以会出现问题,是因为该dll仅通过反射使用,并且由于在编译时没有必要,因此不会在使用中的应用中发布.黑客解决方案是做出无用的引用,只是强制将dll复制.

The issue occurs because this dll is used only through reflection and as it is not necessary in compile time, it is not published in consuming apps. The hack solution is to make an useless reference just to force the dll to be copied.

喜欢:

public class MyAppContext : DbContext
{
    public MyAppContext()
    {
        // hack to force the EntityFramework.SqlServer.dll to be copied when another project references this one
        var forceDllCopy = System.Data.Entity.SqlServer.SqlProviderServices;
    }
}

这篇关于我必须在所有项目中引用Entity Framework 6 dll吗? (不仅是我的DAL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:24