0
獲取同時產生scema與FNH以下錯誤:功能NHibernate - ValidationException實體不具有一個Id映射
ValidationException: The Entity 'TemplateStatusInfo' dows not have an Id mapped.
Class映射定義如下:
[DataContract]
public abstract class Template
{
[DataMember]
public virtual int? Id { get; set; }
[DataMember]
public virtual string Title { get; set; }
[DataMember]
public virtual TemplateStatusInfo TemplateStatus { get; set; }
}
[DataContract]
public class TemplateStatusInfo
{
[DataMember]
public virtual List<string> ValidCodes { get; set; }
[DataMember]
public virtual string TemplateError { get; set; }
}
映射:
public class TemplateMap : ClassMap<Template>
{
public const string TableName = "Template";
public TemplateMap()
{
Table(TableName);
Id(x => x.Id).UnsavedValue(null).GeneratedBy.Native();
Map(x => x.Title).Not.Nullable().Length(150);
DiscriminateSubClassesOnColumn("type");
}
}
public class TemplateStatusInfoMap : ClassMap<TemplateStatusInfo>
{
public TemplateStatusInfoMap()
{
Table(TemplateMap.TableName);
HasMany(x => x.ValidCodes).Table("TemplateValidCodes").KeyColumn("Id").Element("CodeName").AsSet().Cascade.AllDeleteOrphan();
Map(x => x.TemplateError).Length(1000);
}
}
它應該產生兩個表格「模板」(帶有列 - 標識,標題,模板錯誤)和孩子表格「TemplateValidCodes」(帶有列,Id,CodeName)。
任何人都可以請指導我如何可以映射ID爲TemplateStatusInfo這裏(這基本上將Template.Id)?