Fluent Nhibernate - HasMany - 子对象未保存
我有一个 ReportRequest 对象定义为:
public class ReportRequest
{
public virtual Int32? Id { get; set; }
public virtual string Description { get; set; }
public virtual IList<ReportClient> ReportClients{get;set;}
}
ReportClient 定义为:
public class ReportClient
{
public virtual int? Id { get; set; }
public virtual long? ClientId { get; set; }
public virtual string Name { get; set; }
public virtual string EmailAddress { get; set; }
public virtual IList<ReportClient> ChildClients { get; set; }
}
ReportClient 的映射:
public class ReportClientMap : ClassMap<ReportClient>
{
public ReportClientMap()
{
Id(x => x.Id).UnsavedValue(null).GeneratedBy.Native();
Map(x => x.ClientId);
Map(x => x.Name);
Map(x => x.EmailAddress).Length(255);
HasMany<ReportClient>(x => x.ChildClients)
.KeyColumn("ParentId")
.KeyNullable()
.AsBag()
.Inverse()
.ForeignKeyConstraintName("FK_ReportClient_ParentId");
}
}
需要将 ChildClient 保存为 ReportClient 但设置了 ParentId。
虽然 ReportRequest 和 ReportClients 保存得很好,但我面临的问题是 ReportClient.ChildClients 没有被保存。
我什至没有收到任何错误。
有什么想法吗?
I have a ReportRequest object defined as:
public class ReportRequest
{
public virtual Int32? Id { get; set; }
public virtual string Description { get; set; }
public virtual IList<ReportClient> ReportClients{get;set;}
}
and ReportClient is defined as:
public class ReportClient
{
public virtual int? Id { get; set; }
public virtual long? ClientId { get; set; }
public virtual string Name { get; set; }
public virtual string EmailAddress { get; set; }
public virtual IList<ReportClient> ChildClients { get; set; }
}
mapping for ReportClient:
public class ReportClientMap : ClassMap<ReportClient>
{
public ReportClientMap()
{
Id(x => x.Id).UnsavedValue(null).GeneratedBy.Native();
Map(x => x.ClientId);
Map(x => x.Name);
Map(x => x.EmailAddress).Length(255);
HasMany<ReportClient>(x => x.ChildClients)
.KeyColumn("ParentId")
.KeyNullable()
.AsBag()
.Inverse()
.ForeignKeyConstraintName("FK_ReportClient_ParentId");
}
}
ChildClients are required to be saved as ReportClient but with ParentId being set.
Though ReportRequest and ReportClients are being saved fine, but the issue I am facing is ReportClient.ChildClients are not being saved.
I am not even getting any error.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将层叠设置为 ChildClients 属性映射的 save-update :
You need to set cascade to save-update for ChildClients property mapping: