You need to perform the operation as a single unit of work. Don't flush the session after each little piece.
For the future, we really need to see your NH code, not your repository abstraction on top of NH. On Sun, Aug 15, 2010 at 11:06 PM, [email protected] < [email protected]> wrote: > I have a relatively simple application where my main aggregate chain > is: Category -> Forum -> Thread -> Reply. > > My aggregate root repository is CategoryRepository natually. > > I have AllDeleteOrphan set in my HasManyConvention so I can perform > deletes like the following. > > category.RemoveForum(forum); > categoryRepository.Update(category); > > Without it, all that happens is the foreign key get's nulled out, but > the record remains. With it set, it works like it should. However, it > introduces a problem in another action where I need to move a forum to > another category. This code will demonstrate. > > if (currentCategory != destinationCategory) > { > > // this seems to be needed so that the cache doesn't show the forum in > both categories > currentCategory.RemoveForum(forum); > > // THIS LINE CAUSES THE ERROR. by the time it completes, the forum is > an orphan and is deleted. > categoryRepository.Update(currentCategory); > > // now add it to the destination > destinationCategory.AddForum(forum); > > // and save it > categoryRepository.Update(destinationCategory); > > } > > So the question is: what is the proper way to perform this operation? > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
