开发者

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

开发者 https://www.devze.com 2023-02-05 22:56 出处:网络
i have a parent object called Request and a Child object called RequestDate A Request has a list of RequestDates

i have a parent object called Request and a Child object called RequestDate

A Request has a list of 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. 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


You've configured your collection as Inverse, which means the "other side" (i.e. a References in RequestDate) is responsible for managing the relationship.

Therefore, you need to set the reference to the Request in the RequestDate.

If you don't have such a property, then remove the Inverse() call. But NH will do an insert with NULL and then an UPDATE, which might not be what you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消