我需要为每个引用映射一个唯一键(DocumentDetail.Linenumber)。 每个DocumentDetail.Document,密钥DocumentDetail.LineNumber必须是唯一的。 因此,对于每个文档,您需要唯一的行号。
代码:
public class Document : EntityBase<Document>
{
public virtual string Number { get; set; }
public virtual IList<DocumentDetail> Detail { get; set; }
}
public class DocumentDetail : EntityBase<DocumentDetail>
{
public virtual string LineNumber { get; set; }
public virtual Document Document { get; set; }
}
public class DocumentMapping : FluentNHibernate.Mapping.ClassMap<Cradle.DomainEntities.Document>
{
public DocumentMapping()
{
Id(x => x.ID);
Map(x => x.Number).CustomSqlType("varchar(30)").Not.Nullable().Unique();
}
} public class DocumentDetailMapping : FluentNHibernate.Mapping.ClassMap<Cradle.DomainEntities.DocumentDetail>
{
public DocumentDetailMapping()
{
Id(x => x.ID);
Map(x => x.LineNumber).CustomSqlType("varchar(10)"); //this must be unique per document
References(x => x.Document).Not.LazyLoad();
}
}