首页 文章

无法从程序集'XXX'加载'XXX'类型 . at.OnModelCreating(DbModelBuilder modelBuilder)

提问于
浏览
0

在我构建了我的模型后,我想查看它,所以我尝试使用EntityFramework Power工具来直观地获取模型,但是我收到以下错误:

System.Reflection.TargetInvocationException:调用目标抛出了异常 . ---> System.TypeLoadException:无法从程序集“DomainClasses,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null”加载类型“DomainClasses.CompanyLogo” . 位于System.Data.Entity.Entity.InternalContext.CreateModel(LazyInternalContext internalContext)System.Data.Entity.Internal.RetryLazy的System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()中的DataLayer.FinanceModelContext.OnModelCreating(DbModelBuilder modelBuilder) System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext)的System.Data.Entity.LazyInternalContext.get_ModelBeingInitialized()处的System.Data.Entity.Internal.LazyInternalContext.InitializeContext()处的`2.GetValue(TInput输入)


我的域类可能导致错误:

namespace DomainClasses
{
    public class CompanyLogo
    {
        public byte[] Logo { get; set; }

        public int CompanyId { get; set; }

        public virtual Company Company { get; set; }
    }
}

配置文件:

public class CompanyLogoMappings:EntityTypeConfiguration<CompanyLogo>
    {
        public CompanyLogoMappings()
        {
            this.HasKey(c => c.CompanyId);
            this.HasRequired(c => c.Company).WithOptional(cl => cl.CompanyLogo);
        }
    }

1 回答

  • 0

    在许多路径后,我发现为什么会出现此错误 .

    在通过 EF power tools 生成模型后,我添加了域类 CompanyLogo .

    所以我 restart the VS 并构建Domain Classes项目并运行该工具,因此它可以工作 .

相关问题