我正在尝试使用 CodeFirst EF。问题是它为每个域上下文(DbContext)加载了 50 多个表。如果我传递强名称类,则忽略工作,因此编译器知道它是什么,但是硬编码所有忽略将太难。
有没有办法遍历引用的 DLL 中的所有类并将其传递给忽略?我的代码很接近(从帖子中获取代码),但我想不出一种方法来传递带有程序集信息的类类型。我离得那么近又那么远……</p>
Assembly pocoQMAssembly = AssemblyInformationPOCO_QM.Get;
foreach (Type typeInfo in pocoQMAssembly.GetTypes())
{
    //Make sure it is not one of the classes used in DbSet<> 
    if (typeInfo != typeof(tbl_age_groups) ||
        typeInfo != typeof(tbl_axis)
        )
    { 
        //This line will show an error on typeInfo
        //Is there a way to cast it to a class in some way so it likes it?
        modelBuilder.Ignore<typeInfo>();
    }
}
这将暴露程序集以轻松获取它。
public class AssemblyInformationPOCO_QM
{
    public static System.Reflection.Assembly Get
    {
        get
        {
            return typeof(AssemblyInformationPOCO_QM).Assembly;
        }
    }
}