EF7迁移-实体类型“"对应的CLR类型不可实例化 [英] EF7 Migrations - The corresponding CLR type for entity type '' is not instantiable
本文介绍了EF7迁移-实体类型“"对应的CLR类型不可实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用EF7迁移,并在通过继承对 Organization
组织进行建模时陷入困境.
I'm trying to use EF7 migrations and got stuck when I modeled an Organization
model with inheritance.
组织
是抽象类.从其继承的两个具体类分别称为 Individual
和 Company
.
Organization
is an abstract class. There are two concrete classes that inherit from it called Individual
and Company
.
我在 DbContext
中将 Organization
抽象类设置为 DbSet< Organization>
并运行迁移.
I set the Organization
abstract class as DbSet<Organization>
in DbContext
and run migrations.
我正在按照本教程显示以下错误:
实体类型组织"的对应CLR类型不可实例化,并且模型中没有与特定CLR类型相对应的派生实体类型.
The corresponding CLR type for entity type 'Organization' is not instantiable and there is no derived entity type in the model that corresponds to a concrete CLR type.
我该怎么办?
编辑-已更新代码.
组织:
public abstract class Organization
{
public Organization()
{
ChildOrganizations = new HashSet<Organization>();
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public bool Enabled { get; set; }
public bool PaymentNode { get; set; }
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
// virtual
public virtual ICollection<Organization> ChildOrganizations { get; set; }
}
个人
public class Individual : Organization
{
public string SocialSecurityNumber { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
}
公司
public class Company : Organization
{
public string Name { get; set; }
public string OrganizationNumber { get; set; }
}
DbContext
public class CoreDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<Organization> Organization { get; set; }
public CoreDbContext(DbContextOptions<CoreDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
提前谢谢!
推荐答案
查看全文