我有一个如下所示的模型结构:
public abstract class BaseEntity
{
[Key]
public int Id { get; set; }
}
public abstract class AbstractRegistration : BaseEntity
{
public int UserId { get; set; }
}
public class Registration1 : AbstractRegistration
{
public string ReferenceNumber { get; set; }
}
public class Registration2 : AbstractRegistration
{
}
配置部分是:
public class AbstractRegistrationConfig : IEntityTypeConfiguration<AbstractRegistration>
{
public void Configure(EntityTypeBuilder<AbstractRegistration> builder)
{
// map table and schema
builder.ToTable("tbl_reg");
// map properties with actual columns
builder.Property(t => t.Id).HasColumnName("id");
builder.Property(t => t.UserId).HasColumnName("userId");
builder.HasDiscriminator<int>("Id")
.HasValue<AbstractRegistration>(0)
.HasValue<Registration1>(1)
.HasValue<Registration2>(2);
builder.HasDiscriminator<string>("RegNumber")
.HasValue<Registration1>("1");
}
}
public class Registration1Config : IEntityTypeConfiguration<Registration1>
{
public void Configure(EntityTypeBuilder<Registration1> builder)
{
// map table and schema
builder.ToTable("tbl_reg1");
// map properties with actual columns
builder.Property(t => t.Id).HasColumnName("id");
builder.Property(t => t.RegNumber).HasColumnName("reg_num");
}
}
出现的错误是:“实体类型'Registration1'是层次结构的一部分,但未配置鉴别器属性。”
请建议。
EntityFrameworkCore版本=2.0.1.0