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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:59:17+00:00 2026-05-20T12:59:17+00:00

With my only ORM knowledge being L2S/EF, I was surprised when the following code

  • 0

With my only ORM knowledge being L2S/EF, I was surprised when the following code inserted a row into the database before I called repo.Save:

var repo = new UserRepository();
var user = new User { Name = "test" }

repo.Add(user);

//repo.Save();

Repo looks like this:

public void Add(T entity)
{
    session.Save(entity);
}

public void Save()
{
    session.Flush();
}

After some digging, it seems NHibernate needs to make the insert happen right away in order to get the ID of the new entity (since it’s using an auto increment ID). But L2S/EF doesn’t work like this; I can add many entities and save them all at the end.

Question is: is there a way to achieve the same thing with NHibernate, while still using auto increment IDs, and out of interest does anyone know why it works like this?

  • 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-20T12:59:17+00:00Added an answer on May 20, 2026 at 12:59 pm

    Fabio Maulo already blogged about the usage of identity generator a few times. The answer is: use hilo, guid.comb or something like this.

    NHibernate needs the identity because every entity in the session (they are called “persistent entities”) needs to be identified. The identity is also normally used to determine if the record already exists in the database (unsaved value).

    session.Save actually only makes a transient entity persistent. When the database is generating the id, it needs to be stored to get the id. If NH can create the id itself (eg using hilo), it could be stored next time when the session gets flushed.

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

Sidebar

Related Questions

I have the following code, using Django ORM routes =Routes.objects.filter(scheduleid=schedule.id).only('externalid') t_list = [(route.externalid, route.vehicle.name)
Can i use the SqlAlchemy ORM-Mapper to only generate the SQL-Code? With simple tables
Details: Only disable after user clicks the submit button, but before the posting back
I am searching for DAL or ORM (Only ORM no MVC) Solution in PHP5
Bill Karwin has a blog post called Why Should You Use An ORM ?
I want to call only stored procedures on database and fill my C# object
Is there any way in Kohana 3's ORM to run a chunk of code
i am using kohana ORM in order to get some results from the database.
Scenario I'm parsing emails and inserting them a database using an ORM (NHibernate to
The only thing I've found has been; .hang { text-indent: -3em; margin-left: 3em; }

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.