0

我建立我的模型后,我要检讨,所以我尝试使用的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); 
     } 
    } 
+0

您是否已将CompanyLogoMappings添加到配置中? –

+0

@AdilMammadov:是'modelBuilder.Configurations.Add(new CompanyLogoMappings());'但我不知道为什么这个错误 –

回答

0

许多小径后,我觉得为什么这个错误出现。我在EF power tools生成模型后添加了域类CompanyLogo

所以我重新启动VS并构建Domain Classes项目并运行该工具,因此它工作。

相关问题