ctp5 poco,基表对象和域模型

发布于 2024-10-14 19:59:36 字数 863 浏览 1 评论 0原文

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

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;}
}

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

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

to simplify my class/object reuse, I am wondering if I can do that.

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;}
}

My Main purpose here is reusing the classes with additional navigation properties, so that I can easily work with small models which have all the required objects in the model.

I tried implementing this but it is mostly interpreted as inheritance, and it started looking for a Discriminator column etc, so I am wondering if this is even possible without much workaround.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文