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:
- Save Parent, it saves all children
- Update list on parent object (remove some items and add some new items) and save parent it updates children
- 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.
精彩评论