I was very headache on this issue before. I researched, reviewed code lot of times but I didn’t find out the root cause, it was an intermittent issue.
After 1 month, I figured out that this exception was thrown when I saved the entity after I had printed the report.
I felt as “new light at end of the tunnel” lol. I was open my project immediately and read that code block. WOW I saw below line
_currentReceipt.Items = _currentReceipt.Items.OrderBy(x => x.Date_Created).ToList();
Because of this line I faced many times of the exception (below) when I tried to save Receipt data after I had printed report.
NHibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: CLiMS.Data.Platform.Entities.Finance.ExamReceipts.Items;
I changed to no change the items list and used another way. The issue was resolved 🙂
examReceiptItemsBindingSource.DataSource = _currentReceipt.Items.OrderBy(x => x.Date_Created)
I hope my sharing will help you to save your time :).