ctp5 poco,基表对象和域模型
为了简化我的类/对象重用,我想知道我是否可以做到这一点。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论