假設我有三個類。實例化A是有效的,但是也存在特殊情況B和D,它們是A的子類,增加了額外的信息。流利的NHibernate - 如何映射一個子類的一對一?
我該如何做(流利的)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
}
我嘗試以下,但它並沒有在所有的工作:
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();
}
}
埃裏克,偉大的職位。 – Berryl 2009-07-23 12:39:00