Suppose I have three classes. It is valid to instantiate A, but there are also special cases B and D which subclass A, adding additional information.
How would I do the mapping files for this in (fluent) NHibernate?
public class A
{
public int ID { get; set;}
public string CommonProperty1 { get; set; }
public string CommonProperty2 { get; set; }
}
public class B : A
{
public string BSpecificProperty1 { get; set; } //not null
public string BSpecificProperty2 { get; set; } //not null
}
public class D : A
{
public string DSpecificProperty { get; set; } //not null
}
I tried the following, but it doesn't work at all:
public class AMap : ClassMap<A>
{
public AMap()
{
Id(x => x.ID);
Map(x => x.CommonProperty1);
Map(x => x.CommonProperty2);
}
}
public class BMap : ClassMap<B>
{
public BMap()
{
References(x => x.ID);
Map(x => x.BSpecificProperty1)
.CanNotBeNull();
Map(x => x.BSpecificProperty2)
.CanNotBeNull();
}
}
public class DMap : ClassMap<D>
{
public DMap()
{
References(x => x.ID);
Map(x => x.DSpecificProperty)
.CanNotBeNull();
}
}