title: All delete orphan for Nhibernate
body: <p>So I have a parent object called order and a collection of child objects called orderLineItems with Cascade set to All-Delete-orphan in nHibernate. Here is my code.</p>
  
  <pre><code>using( var session = _sessionManager.GetSession())
          using (var transaction = session.BeginTransaction())
          {
  
              var order = _repository.GetOrderEagerlyByOrderId(session, fromDb.Id);
              var now = DateTime.Now;
              const string user = "GNB\\Username";
              var future = now.AddYears(1);
              var taxType = new TaxType(0, "Code", "AlternateNameE", "AlternateNameF", "NameE", "NameF", "DescriptionE", "DescriptionF", 13, now, future, user, now, user, now);
              var _serviceCatRep = new ServiceCatalogueRepository();
  
              var serviceCatalogueItem = _serviceCatRep.GetServiceCatalogueItemByCode(session, "VR-PASS");
              var orderLineItem1 = new OrderLineItem(0, null, "DescriptionE", "DescriptionF", 1, 10, null, null, 5, false, serviceCatalogueItem, null, user, now, user, future);
  
              order.OrderLineItems.Clear();
  
              order.OrderLineItems = order.OrderLineItems == null ? new List&lt;IOrderLineItem&gt; { orderLineItem1 } : new List&lt;IOrderLineItem&gt;(order.OrderLineItems) { orderLineItem1 };
  
              _repository.SaveOrUpdate(session, order);
              transaction.Commit();
          }
  </code></pre>
  
  <p>It fails on <code>transaction.Commit();</code> with the error:</p>
  
  <blockquote>
    <p>NHibernate.HibernateException : A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance</p>
  </blockquote>
  
  <p>Also, what are the differences between all and all-delete-orphan with an example.</p>