1

为了简化我的类/对象重用,我想知道我是否可以这样做。

public class InvoiceTbl
{
    public Guid InvoiceId {get; set;}
    ...
}

public class InvoiceLineTbl
{
    public Guid InvoiceId {get; set;}
    public Guid InvoiceLineId {get; set;}
    ...
}

public class InvoiceBaseContext: DbContext
{
    DbSet<InvoiceTbl> Invoices {get; set;}
    DbSet<InvoiceLineTbl> InvoiceLines {get; set;}
}

public Invoice : InvoiceTbl
{
    public virtual ICollection<InvoiceLine> Lines {get; set;}
}
public InvoiceLine: InvoiceLineTbl
{
    public Invoice Header {get; set;}
}

public InvoiceContext : DbContext
{
     public DbSet<Invoice> Invoices {get; set;}
     public DbSet<InvoiceLine> InvoiceLines {get; set;}
}

我在这里的主要目的是重用具有附加导航属性的类,以便我可以轻松地使用在模型中具有所有必需对象的小型模型。

我尝试实现它,但它主要被解释为继承,它开始寻找鉴别器列等,所以我想知道这是否可能在没有太多解决方法的情况下实现。

4

0 回答 0