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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:34:46+00:00 2026-05-22T21:34:46+00:00

I have these tables/classes (example): table FirstTable ( Id INTEGER NOT NULL DEFAULT AUTOINCREMENT,

  • 0

I have these tables/classes (example):

table FirstTable (
    Id INTEGER NOT NULL DEFAULT AUTOINCREMENT, 
    Name VARCHAR(100) NOT NULL,
    Document VARCHAR(20) NOT NULL
)

table SecondTable (
    Id INTEGER NOT NULL,
    Something VARCHAR(100) NULL,
    FOREIGN KEY (Id) REFERENCES FirstTable (Id)
)

public class FirstClass {
    public string Name { get; set; }
    public string Document { get; set; }
    public SecondClass SecondClass { get; set; }
}

public class SecondClass {
    public string Something { get; set; }
    public FirstClass FirstClass { get; set; }
}

The mapping is:

public class FirstClassMap : ClassMap<FirtsClass> {
    Table("FirstTable");
    Id(x => x.Id).GeneratedBy.Identity();
    Map(x => x.Name);
    Map(x => x.Document);
    References(x => x.SecondClass, "Id").ForeignKey();
}

public class SecondClassMap : ClassMap<SecondClass> {
    Table("SecondTable");
    Id(x => x.Id).GeneratedBy.Foreign("FirstClass");
    Max(x => x.Something);
    HasOne(x => x.FirstClass).PropertyRef(x => x.SecondClass).Cascade.SaveUpdate();
}

FirstClass can have (0,1) SecondClass, and SecondClass can have (1,1) FirstClass.

The bellow code return the error “attempted to assign id from null one-to-one property: SecondClass”

var test = new SecondClass();
test.FirstClass = new FirstClass();

test.Something = "New test";
test.FirstClass.Name = "My name";
test.FirstClass.Document = "My document";
// ... commands to save.
  • 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-22T21:34:46+00:00Added an answer on May 22, 2026 at 9:34 pm

    It seems like NH is trying to save SecondClass first and fails to grab a generated ID from the not yet saved FirstClass.

    Try to move the .Cascade.SaveUpdate() to the References declaration in FirstClassMap and call the save command on FirstClass.

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

Sidebar

Related Questions

I have these tables: customer -------- customer_id int name varchar(255) order ----- order_id int
Suppose you have these tables: Table Name: Salesman Fields: S_ID(Primary Key), Name Table Name:
Here's an example: If I have these classes class Author(models.Model): name = models.CharField(max_length=45) class
Hi every one I have these classe @Entity @Table(name = login, uniqueConstraints={@UniqueConstraint(columnNames={username_fk})}) public class
If I have these two tables: <table> <tr> <td>Small Length Content</td> </tr> </table> <table>
i have the two classes Person and Attribut, in short: @Entity @Indexed @Table(name=persons) public
I have an HTML page that has many nested tables, for example table for
I have these two database tables: locations id name users id location_id last_name first_name
I have a few classes, such as those that outline database table structure or
I have these tables: Projects(projectID, CreatedByID) Employees(empID,depID) Departments(depID,OfficeID) Offices(officeID) CreatedByID is a foreign key

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.