0
我有这个样本项目:继承和与MVC基本抽象类的关系,EF
型号:
public class Country
{
public int ID{get; set;}
public string CountryName{get; set;}
}
public abstract class Subject
{
public int CountryID{get; set;}
}
public class Person : Subject
{
public string PersonName{get; set;}
}
public class Company : Subjet
{
public string CompanyName{get; set;}
}
语境:
public class SampleContext : DbContext
{
public DbSet<Contry> Countries{get; set;}
public DbSet<Person> Persons{get; set;}
public DbSet<Company> Companies{get; set;}
modelBuilder.Entity<Person>().Map(m => { m.MapInheritedProperties();ToTable("Person"); });
modelBuilder.Entity<Company>().Map(m => { m.MapInheritedProperties();ToTable("Company"); });
}
而且我得到这个错误。
错误3013:问题在映射片段开始行XXX:缺少表映射:从表主题(CountryID)
外键约束Subject_Country但是,主题是抽象的,我不以DB惯于这样的表。当我使用Subject类只有像int或字符串的参数时,一切正常。但是当我想要使用这种关系时,我得到这个错误。
非常感谢您的帮助。
公共DbSet国家{获得;设置;}应该公开DbSet Countries {get;组;} –