c# - Exclude columns in database and mapping with Nhibernate -


i have following situation

enter image description here

one purchaseorder has many line items , 1 invoice has many line items. purchaseorder , invoice quite different. if specific lineitem has 1 puchaseorder hasn't invoice , vice versa. need persist these relationships. in app i'm using nhibernate.

i thought on database, lineitems table have column foreign key purchaseorder , column foreign key invoice.

what best approach this?

model

you map lineitem heirarchy.

lineitem heirarchy

public class lineitem {    //common properties of lineitem }  public class purchaselineitem : lineitem  {      public purchaseorder purchaseorder { get; set; } }  public class invoicelineitem : lineitem  {      public invoice invoice { get; set; } } 

modify purchaseorder , invoice refer specific child

purchase order :

public class purchaseorder {     public ilist<purchaselineitems> lineitems { get; set; } } 

invoice :

public class invoice {    public ilist<invoicelineitems>  lineitems { get; set; } } 

database

on database side consider mapping 2 items in different tables unnecessarily increase joins. adopt single table entire heirarchy type descriminator.

  1. the specific classes avoid confusion in rest of code holder of lineitem either purchaseorder or invoice nullable , improve readability.
  2. you improve design making adding purchaseorder parameter on purchaselineitem (similarly invoice constructor parameter invoicelineitem) make sure these entities not initialized without respective holders.

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -