我建立我的模型后,我要检讨,所以我尝试使用的EntityFramework电动工具在视觉上得到的模型,但我得到了以下错误:无法从程序集“XXX”加载类型“XXX”。 at.OnModelCreating(DbModelBuilder模型构建器)
的System.Reflection .TargetInvocationException:异常已被调用的目标抛出 。 ---> System.TypeLoadException:可能 未从程序集加载类型'DomainClasses.CompanyLogo' 'DomainClasses,Version = 1.0.0.0,Culture = neutral, PublicKeyToken = null'。在 DataLayer.FinanceModelContext.OnModelCreating(DbModelBuilder 模型构建器)在 System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()
在 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)在 系统.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());'但我不知道为什么这个错误 –