【发布时间】:2016-07-29 13:25:50
【问题描述】:
建立模型后,我想对其进行审查,因此我尝试使用 EntityFramework Power 工具直观地获取模型,但出现以下错误:
System.Reflection.TargetInvocationException:已抛出异常 通过调用的目标。 ---> System.TypeLoadException:可以 不从程序集中加载类型“DomainClasses.CompanyLogo” '域类,版本=1.0.0.0,文化=中性, PublicKeyToken=null'。在 DataLayer.FinanceModelContext.OnModelCreating(DbModelBuilder 模型构建器)在 System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()
在 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext 内部上下文)在 System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput 输入)在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
在 System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized() 在 System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext
可能导致错误的我的域类:
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);
}
}
【问题讨论】:
-
您是否已将 CompanyLogoMappings 添加到配置中?
-
@AdilMammadov : 是的
modelBuilder.Configurations.Add(new CompanyLogoMappings());但我不知道为什么会出现这个错误
标签: c# entity-framework visual-studio-2015 ef-code-first entity-framework-6