流利的Nhibernate - 一对多映射问题

时间:2011-03-17 14:46:38

标签: fluent-nhibernate mapping

我尝试在流畅的nhibernate中进行一对多映射时得到NHibernate.MappingException。 以下是我的实体及其映射类的片段:

public class ReportRequest : IReportRequestToBeFullyLoaded
{
    public virtual Int32? Id { get; set; }
    public virtual string Description { get; set; }
    public virtual ISet<ReportOutputEmail> ReportOutputEmails { get; set; }
}

public class ReportOutputEmail
{
    public virtual string RecipientAddress { get; set; }
    public virtual string Message { get; set; }
    public virtual ReportRequest ReportRequest { get; set; }
}

public class ReportRequestMap : ClassMap<ReportRequest>
{
    public ReportRequestMap()
    {
        Table("ReportRequest");
        Id(x => x.Id).UnsavedValue(null).GeneratedBy.Native();
        Map(x => x.Description);
        HasMany(x => x.ReportOutputEmails).Table("ReportOutputEmail")
            .ForeignKeyConstraintName("FK_ReportOutputEmail_ReportRequest")
            .KeyColumn("ReportRequestId")
            .AsSet()
            .Inverse()
            .Cascade.AllDeleteOrphan();
    }
}

public class ReportOutputEmailMap: ClassMap<ReportOutputEmail>
{
    public ReportOutputEmailMap()
    {
        References(x => x.ReportRequest)
            .ForeignKey("FK_ReportOutputEmail_ReportRequest")
            .Column("ReportRequestId");
        Map(x => x.RecipientAddress);
        Map(x => x.Message);
    }
}

ReportRequest-&gt; ReportOutputEmail 之间的一对多映射存在一些问题,
得到错误:

Error: NHibernate.MappingException: (XmlDocument)(3,6): XML validation error: The  
element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element  
'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements  expected:  'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in     namespace  'urn:nhibernate-mapping-2.2'.

任何人都可以帮忙搞清楚。

谢谢!

1 个答案:

答案 0 :(得分:2)

您的ReportOutputEmail没有身份,如果它成为一个实体,则需要一个身份。

另外,我建议你升级你的Fluent NHibernate副本,因为从1.1开始就会以更有用的方式报告(你会收到一条身份缺失的消息)。