Załóżmy, że mam trzy klasy. Ważne jest, aby utworzyć instancję A, ale są również specjalne przypadki B i D, które podklasą A, dodając dodatkowe informacje.Fluent NHibernate - jak zmapować podklasę jeden-do-jednego?
Jak zrobić pliki odwzorowań dla tego (płynnego) 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
}
Próbowałem następujących, ale to nie działa w ogóle:
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();
}
}
Erik, wielki post. – Berryl