简体   繁体   English

如何不担心Nhibernate中的子对象(列表)

[英]How to not worry about children objects (lists) in nhibernate

i have a parent object called Request and a Child object called RequestDate 我有一个名为Request的父对象和一个名为RequestDate的子对象

A Request has a list of RequestDates 一个请求有一个RequestDates列表

i want to have mappings so when i: 我想有映射,所以当我:

  1. Save Parent, it saves all children 拯救父母,拯救所有孩子
  2. Update list on parent object (remove some items and add some new items) and save parent it updates children 更新父对象上的列表(删除一些项目并添加一些新项目)并保存父对象,以更新子对象
  3. Delete parent will delete all children. 删除父级将删除所有子级。

is this possible. 这可能吗。 i tried using this syntax but it doesn't seem to work: 我尝试使用此语法,但似乎不起作用:

 HasMany(x => x.RequestDates)
     .AsBag()
     .Inverse()
     .Cascade.AllDeleteOrphan()
     .Fetch.Select()
     .BatchSize(80); 

the issue is around #2. 问题在#2附近。 what is the way to update the list of items. 什么是更新项目列表的方法。 I am calling Remove() to get rid of some and then calling Add() to add new ones 我正在调用Remove()摆脱一些,然后调用Add()添加新的

You've configured your collection as Inverse , which means the "other side" (ie a References in RequestDate) is responsible for managing the relationship. 您已将集合配置为Inverse ,这意味着“另一面”(即RequestDate中的References )负责管理关系。

Therefore, you need to set the reference to the Request in the RequestDate. 因此,您需要在RequestDate中设置对请求的引用。

If you don't have such a property, then remove the Inverse() call. 如果没有这样的属性,则删除Inverse()调用。 But NH will do an insert with NULL and then an UPDATE, which might not be what you want. 但是NH将先执行NULL插入操作,然后执行UPDATE操作,这可能不是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM