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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:32:54+00:00 2026-05-25T22:32:54+00:00

I currently have this code. tableB = new TableB { TableA = tableA, };

  • 0

I currently have this code.

                    tableB = new TableB
                    {
                        TableA = tableA,
                    };

                    List<TableC> tableC = locations.Select(location => new TableC
                    {
                        TableB = tableB
                    }).ToList();

                    tableB.TableC = tableC;

                    tableA.TableB.Add(tableB);
nhibernate.Create(a);
nhibernate.Commit();

The above code works but I find it kinda weird that I have do it like this.

I would like to do something like

  tableB = new TableB
                        {
                            TableA = tableA,
                            TableC = MakeAllTableCs()
                        };

                        tableA.TableB.Add(tableB);
    nhibernate.Create(a);
    nhibernate.Commit();

The collection of tableC’s is being made in memory and and when I try to do a create I get

not-null property references a null or transient value

It seems that it want’s a reference to TableB for each one in the collection of TableC. It seems kinda odd to do this seeing that I am sticking in the TableB object. I would have hoped that it would have figured that out and used it as a reference.

Is there anyway that I can do it so I don’t need to have a reference of TableB in each of my TableC objects?

Edit Mapping

     public class TableAMap : ClassMap<TableA>
        {
            public TableAMap()
            {

                Id(x => x.Id).GeneratedBy.GuidComb();
                HasMany(x => x.).Cascade.All().Inverse();
            }
        }


 public class TableBMap : ClassMap<TableB>
    {
        public TableBMap ()
        {

            Id(x => x.Id).GeneratedBy.GuidComb();
      References(x => x.TableA).Not.Nullable();
            HasMany(x => x.TableC).Cascade.All().Inverse();

        }

    }

  public class TableCMap : ClassMap<TableC>
    {
        public TableCMap ()
        {
            Id(x => x.Id).GeneratedBy.GuidComb();
           References(x => x.TableB).Not.Nullable();
        }
    }
  • 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-25T22:32:54+00:00Added an answer on May 25, 2026 at 10:32 pm

    Hard to say without your mappings and real NHibernate code (where you call session.Save()) but most likely you are not saving the new TableB objects and also don’t have any cascade setting on TableA.b (you need one of those).

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

Sidebar

Related Questions

Using dotnet 2.0. I currently have code like this : DataView dv = new
We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
Is there a better way to do this jquery code? Currently I have to
There is probably is simple fix for this but I currently have code similar
I have this code: Dim pathString As String = HttpContext.Current.Request.MapPath(Banking.mdb) Dim odbconBanking As New
I have a long list generated from a simple mysql select query. Currently (shown
As a beginner in Ocaml, I have this current working code: ... let ch_in
I have trouble finding way to correctly refactor this code so that there would
I am having a bit of difficulty with this current code I have set
This is my current scenario: I have checked in my grails app code +

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.