Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7989825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:51:12+00:00 2026-06-04T12:51:12+00:00

So I have a parent object called order and a collection of child objects

  • 0

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.

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<IOrderLineItem> { orderLineItem1 } : new List<IOrderLineItem>(order.OrderLineItems) { orderLineItem1 };

            _repository.SaveOrUpdate(session, order);
            transaction.Commit();
        }

It fails on transaction.Commit(); with the error:

NHibernate.HibernateException : A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

Also, what are the differences between all and all-delete-orphan with an example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:51:13+00:00Added an answer on June 4, 2026 at 12:51 pm

    You’ve got:

    order.OrderLineItems.Clear();
    
    order.OrderLineItems = order.OrderLineItems == null 
        ? new List<IOrderLineItem> { orderLineItem1 } 
        : new List<IOrderLineItem>(order.OrderLineItems) { orderLineItem1 };
    

    firstly if order.OrderLineItems is null then the order.OrderLineItems.Clear() will throw a NullReferenceException, secondly the problem is arising because you’re assigning a new List to order.OrderLineItems so NHibernate doesn’t know what to cascade the delete for. To get it to work, just change the second line to:

    order.OrderLineItems.Add(orderLineItem1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parent object called Page that has a List of objects called
I have two tables without any cascade deleting. I want to delete parent object
I have a parent class which contains a child object. I am using set
I have a parent-child view model object structure set up and need to update
I have a Parent/Child object/mapping as follows: class Parent { int Id; string name;
I have this huge domain object(say parent) which contains other domain objects. It takes
I have a class called Parent , and I'm storing these object's in the
I have a business object, which is a composite of child objects. I am
I have a list of addresses contained in a parent object called Branch. Branch
I have an object called Device . A Device can have one parent Device

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.