vb.net - Nhibernate and inheriting mapping-by-code -


i have 2 classes, 1 inheriting other. first shows summary view of data (4+ columns) , child shows detail view (40+ columns). both classes accessing same table , share same columns being accessed.

can child class inherit parent class have change mappings in 1 place? i'd rather not have duplicate code running rampant.

e.g.:

public class parent  public overridable property myprop string  public overridable property myprop2 string end class  public class child : inherits parent  public overridable property myprop3 string end class 

i want this:

public class parentmapping     inherits classmapping(of parent) public sub new()  me.property(function(x) x.myprop, sub(y) y.column("myprop"))  me.property(function(x) x.myprop2, sub(y) y.column("myprop2")) end sub end class  public class childmapping inherits subclassmapping(of child)  public sub new()   ' want able inherit mappings of parent here.   mybase.new()    me.property(function(x) x.myprop3, sub(y) y.column("myprop3"))  end sub end class 

if want child subclass of parent in db also, you'll need discriminator column.

if want reuse code share mapping base class

public abstract class parentchildmapping<t> : classmapping<t> t : parent {     public parentchildmapping()     {     // map shared properties here     } }  public class parentmapping : parentchildmapping<parent> { }  public class childmapping : parentchildmapping<child> {     public childmapping()     {     // map additional properties here     } } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -