Well, I'm at college at the moment, so I do not have the exact code, I
will post that when I get home,
In the meantime, here is what I can tell you.
public void Update(T entity)
{
using (ITransaction tx = Session,BeginTransaction())
{
Session.Update(entity);
tx.Commit();
// see comment below on this line
Session.Clear();
}
}
** I got the following code to work, but it requires the commented
line above so that subsequent selects do not show the entity as being
owned by two separate parents because of the NH caching. The db
changes work.
if (currentCategory != destinationCategory)
{
destinationCategory.AddForum(forum);
categoryRepository.Updaet(destination);
}
So let ne refine my original question to this instead: is there a
better way of refreshing things other than calling Clear()?
On Aug 16, 8:40 am, Jason Dentler <[email protected]> wrote:
> 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.- Hide quoted text -
>
> - Show quoted text -
--
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.