我有一個映射的問題,簡化我的關係看起來像這樣。 我有父類:流利NHibernate的子類映射使用DiscriminateSubClassesOnColumn問題
public abstract class DocumentType
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
和兩個子類:
public class UploadedFileDocument : DocumentType
{
}
public class ApplicationFormDocument : DocumentType
{
}
這樣映射:
public DocumentTypeMap()
{
Schema("Core");
Id(x => x.Id);
Map(x => x.Name).Length(128).Not.Nullable();
DiscriminateSubClassesOnColumn("Type");
}
public class UploadedFileDocumentMap : SubclassMap<UploadedFileDocument>
{
}
public class ApplicationFormDocumentMap : SubclassMap<ApplicationFormDocument>
{
}
然後,我有一個FK另一個實體DocumentType,這樣映射:
public FileConversionMap()
{
Schema("Core");
Id(x => x.Id);
References(x => x.Application).Not.Nullable();
References(x => x.DocumentType).Not.Nullable().Fetch.Select();
}
我的問題是,當我取回從DB行是這樣的:
Session.Query<FileConversion>().AsQueryable();
所有行回來與DocumentType
存在DocumentType
類型,不是孩子的類型(即實際類型的屬性,即。當我做.GetType()
,要麼UploadedFileDocument
或ApplicationFormDocument
)
道歉,如果這只是我昏暗。但是,我怎樣才能確定我有哪種類型的DocumentType
...是我的映射錯誤?
我結束了一個不同的數據庫模式,所以一切都改變了我,但大衛的回答是非常有幫助的,我敢肯定他是對的,所以標記爲接受的答案 – soupy1976