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 6793819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:08:47+00:00 2026-05-26T18:08:47+00:00

I have a Parent class with two lists of Child classes public class Parent

  • 0

I have a Parent class with two lists of Child classes

    public class Parent
    {
        ...

        public virtual ICollection<Foo> Foo{ get; set; }

        public virtual ICollection<Bae> Bar{ get; set; }
    }

    public class Foo
    {
        ...

        public virtual Parent Parent{ get; set; }
    }

    public class Bar
    {
        ...

        public virtual Parent Parent{ get; set; }
    }

The mappings are

        public ParentMap()
        {
            ...

            HasMany(m => m.Foo).AsSet().Cascade.All();
            HasMany(m => m.Bar).AsSet().Cascade.All();
        }

        public FooMap()
        {
            ...

            References(m => m.Parent);
        }

        public BarMap()
        {
            ...

            References(m => m.Parent);
        }

Whenever I save the parent object I get

INSERT Parent ...
INSERT Foo with Parent_id set to NULL
INSERT Bar with Parent_id set to NULL
UPDATE Foo set Parent_id to Parent id
UPDATE Bar set Parent_id to Parent id

Is there a way apart from setting the relationship to Inverse to avoid the extra update?

  • 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-05-26T18:08:47+00:00Added an answer on May 26, 2026 at 6:08 pm

    If you have a bidirectional assiciation you should set the HasMany side to inverse, this is the most common way.

    Another possibility is setting the parent reference to Not.Insert().Not.Update(), then the parent property will be completely ignored for insert/updates.

    If you don’t need the reference from child to parent just remove it from the class and mapping so you only have the collection.

    For the second and third way you can additionally set Not.KeyNullable() on the HasMany, this makes sure that NHibernate inserts the new row with the parent ID already set and avoids the additional update statement (this feature requires NHibernate 3.2.0).

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

Sidebar

Related Questions

I have two entities: public class Parent() { public ICollection<Child> Children { get; set;
I have two classes: public class Parent { public virtual long? ID { get;
I have a MustInherit Parent class with two Child classes which Inherit from the
I have two classes with a parent-child relationship (the Parent class has-a Child class),
I have a parent class which contains a child object. I am using set
In Django, when you have a parent class and multiple child classes that inherit
New to FluentNHibernate =D I have a parent/children classes as follows: public class Parent
Let's say I have a simple parent->child class structure as shown below Public Class
I have two classes named BaseCatalog and City. BaseCatalog is the parent class of
I'm using EF4.1 POCO. I have two tables [Table(Parent)] public class Parent { public

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.