c# - nHibernate Mapping BaseClass to Multiple tables -
i have group of objects share similar properties, inherit these base class. here simple example of doing.
i have 2 objects, employee
, customer
have corresponding tables. each contain list of addresses. address
class shared between 2 objects, reside in 2 seperate tables employeeaddress
, customeraddress
.
employeeaddress - employeeid uniqueidentifier address varchar (50) zipcode varchar (10) city varchar (20) state id not null customeraddress - customerid uniqueidentifier address varchar (50) zipcode varchar (10) city varchar (20) state id not null
how can map address object 2 seperate tables? want able pull data either employeeaddress
or customeraddress
table when needs to.
i have tried:
(employeemap) hasmany(x => x.addresses).table("employeeaddress").keycolumn("employeeid");
but nhibernate complained address
class did not have own mapping class.
(addressmap) id(x => x.id); map(x => x.parentitemid); //generic way reference employeeid or customerid // can't specify column name should // using
but nhibernate tried grabbing data out of address
table doesn't exist, , column names wrong.
fyi: not able combine 2 address tables one.
you can create mappings inherit each other
base mapping class contains duplicated values:
public class addressbasemap<t> : classmap<t> t : address { public addressbasemap() { map(x => x.address); //etc } } public class customeraddressmap : addressbasemap<customeraddress> { public customeraddressmap() { table("customeraddress"); } }
i suggest use of components can encapsulate of fields single class.
Comments
Post a Comment