kia*_*osh 6 c# entity-framework ef-code-first ef-fluent-api
使用C#Entity Framework Codefirst和Fluent Api,我有一个TPC继承的奇怪问题.我有3类命名Person
,Invoice
并且PeriodicInvoice
你可以看到下面.以下是我的代码摘要:
Invoice
class及其配置类:
public class Invoice : InvoiceBase
{
public Person User { get; set; }
}
public class InvoiceConfig : EntityTypeConfiguration<Invoice>
{
public InvoiceConfig()
{
this.Map(m => { m.MapInheritedProperties(); m.ToTable("Invoices"); });
}
}
Run Code Online (Sandbox Code Playgroud)
PeriodicInvoice
类及其配置:
public class PeriodicInvoice : InvoiceBase
{
// Some extra properties.
}
public class PeriodicInvoiceConfig : EntityTypeConfiguration<PeriodicInvoice>
{
public PeriodicInvoiceConfig()
{
this.Property(x => x.SuspendOnExpire).IsRequired();
this.Map(m => { m.MapInheritedProperties(); m.toTable("PeriodicInvoices"); });
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,会出现此错误:
实体类型"发票"和"人员"之间的关联"Invoice_User"无效.在TPC层次结构中,仅允许在大多数派生类型上使用独立关联.
我知道这意味着我应该将属性包含在User
类中PeriodicInvoice
,不要在课堂上使用它Invoice
.
但是,有没有其他方法可以解决这个问题?谢谢.
归档时间: |
|
查看次数: |
1734 次 |
最近记录: |