Fluent Nhibernate - 一对多映射问题
我在尝试在流畅的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
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).