I have an intermittent problem that I haven't been able to recreate
locally. What appears to be happening is that for no obvious reason
during an edit of a child entity and saving the parent containing the
collection the parent association on the child entity is removed in
the database. Effectively orphaning the child entity.

Here is the fluent mapping:

 mapping.HasMany<ExpenseItem>(x =>
x.ExpenseItems).Cascade.AllDeleteOrphan();

The only other thing is that this entity can also be directly saved
(it is also aggregate root), but during testing this has not be shown
to remove the parent association.

There are no references to the parent itself in the child object it is
all handled by Nhibernate.

There is also no possibility of assigning the same child entity to
another parent as expense items cannot be added outside of their
parent directly. See code below.

 public virtual ExpenseItem AddNewExpenseItem(ExpenseAnalysis
analysis,
            string recipientName,
            string purchaseAccountReference,
            string expenseDescription,
            string expenseNotes,
            Money value,
            VATAnalysis vat)
        {
            Validate.IsNotNull<ExpenseAnalysis>(analysis);
            Validate.IsNotNull(expenseDescription);
....


            ExpenseItem newExpenseItem = new ExpenseItem(analysis,
                recipientName,
                purchaseAccountReference,
                expenseDescription,
                expenseNotes,
                value,
                vat,
                expenseItemUniqueReference,
                true,
                Candidate.Assessment);
            _expenseItems.Add(newExpenseItem);
....

This method has always worked in the past.

-- 
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.

Reply via email to