c# - Exclude columns in database and mapping with Nhibernate -
i have following situation
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.
- the specific classes avoid confusion in rest of code holder of
lineitem
eitherpurchaseorder
orinvoice
nullable , improve readability. - you improve design making adding
purchaseorder
parameter onpurchaselineitem
(similarlyinvoice
constructor parameterinvoicelineitem
) make sure these entities not initialized without respective holders.
Comments
Post a Comment