Fluent Nhibernate - 一对多映射问题

发布于 2024-10-23 14:30:19 字数 1942 浏览 2 评论 0原文

我在尝试在流畅的 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->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'.

任何人都可以帮忙解决。

谢谢你!

I am getting NHibernate.MappingException while trying to do one-to-many mapping in fluent nhibernate.
Below are the snippets from my entity and their mapping classes:

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);
    }
}

There is some issue with one-to-many mapping between ReportRequest->ReportOutputEmail,
Getting error:

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'.

Can anyone help figuring out.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残花月 2024-10-30 14:30:19

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

另外,我建议您升级 Fluent NHibernate 的副本,因为自 1.1 版本以来,报告的方式更加有用(您会收到身份缺失消息)。

Your ReportOutputEmail doesn't have an identity, it'll need one if its going to be an entity.

Also, I recommend you upgrade your copy of Fluent NHibernate, as this is reported in a much more helpful manner since 1.1 (you'd get an identity missing message).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文