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

  • Home
  • SEARCH
  • 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 8457799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:54:13+00:00 2026-06-10T12:54:13+00:00

I’ve searched so many places and still can’t find the a answer I’m looking

  • 0

I’ve searched so many places and still can’t find the a answer I’m looking for.

I’m using NHibernate 3.2 – Mapping by Code

I Have the following Mapping files:

public class ParentMapping: EntityMapping<Parent>
{
        public ParentMapping()
        {
            Set(x => x.Children, map =>
                                           {
                                               map.Cascade(Cascade.All);
                                               map.Inverse(true);
                                           }, r => r.OneToMany());
        }
}

public class ChildMapping: JoinedSubclassMapping<Child> // This is a subclass of something else.
{
        public RequiredSkillMapping()
        {
            ManyToOne(x => x.Parent, map => { map.NotNullable(true); });
        }
}

The cascade save works fine.

session.Save(parent) will save the children and associate them correctly.

When I try to call:

var parent = session.Get<Parent>(1);
parent.Children.Clear();

session.Save(parent); or session.SaveOrUpdate(parent) or session.Update(parent)

The entities stay associated to the parent.

I had it working by calling:

foreach(var child in parent.Children)
{
session.Delete(child);
}

parent.Children.Clear();

I was hoping that there would be a way to just save the parent?

Cheers,

James

  • 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-10T12:54:14+00:00Added an answer on June 10, 2026 at 12:54 pm

    Cascade means that operations on the parent are cascaded to the child.

    • When inserting the parent, the children are inserted too.
    • When deleting the parent, the children are deleted too.
    • Update is special in NH, but it also means when calling update with the parent, that the children are “updated” too.
    • and so on

    The collection itself belongs to the parent, so changes on the collection are stored with the parent. But there is no reason to delete the children when they are not in the collection anymore. NH can’t know if you need them for anything else.

    There is cascade-delete-orphans.

    map.Cascade(Cascade.All | Cascade.DeleteOrphans)
    

    It means that items that had been in the collection, and are removed from the collection get deleted. It may be useful in your case. Note that it is not possible to use items for anything after removing from the collection. You can’t even add them to another parent.

    To make NH remove unused items automatically correctly in every case would require persistent garbage collection. This is highly inefficient and is not implemented by NH.

    “foreach child delete” is OK. That’s something you may have to do to tell NH when the children are not used anymore and need deletion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.