c# - How-to: Mapping (NHibernate) multiple classes with different business logic from the same table? -
i working brownfield database contains table holds data 3 different sorts of business. has salesorders , orderlines. in old application, able add 3 types of orderlines each salesorder: products, hourly rates , text lines. 15 years ago, quick , dirty solution easy queries in delphi lines in 1 datagrid. every
now trying build object model in c# using nhibernate. i've made 3 seperate entities without base class, due fact these 3 line types have no real business logical connection. however, want these 3 types 1 list can order them.
i've considered using inheritence, table per class, table meets requirements (no columns not-null restraint). isn't logical step though, since business per type different (only things in common userid, description , remarks). perhaps component? how map properties 3 different classes without base class or kind of link except table name?
i hope guys understood wrote. have no real code yet, sketching stuff on paper on how deal code.
anyone here can me on way?
kind regards, ted
you put interface on 3 entities , map base class, same table:
interface iwhatever { // central id whole table int id { get; set; } // may more properties } class product : iwhatever { // ... } class hourlyrate : iwhatever { // ... } class textlines : iwhatever { // ... }
mapping:
<class name="iwhatever" table="mybigtable"> <id .../> <discriminator column="type"/> <subclass name="product" discriminator-value="p"> <!-- ... --> </subclass> <subclass name="hourlyrate" discriminator-value="hr"> <!-- ... --> </subclass> <subclass name="textlines" discriminator-value="tl"> <!-- ... --> </subclass> </class>
Comments
Post a Comment