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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:10:00+00:00 2026-05-13T22:10:00+00:00

I’m creating a simple Windows Forms application with NHibernate and I’m a bit confused

  • 0

I’m creating a simple Windows Forms application with NHibernate and I’m a bit confused about how I’m supposed to use it. To quote the manual:

ISession (NHibernate.ISession)

A single-threaded, short-lived object representing a conversation between the application and the persistent store. Wraps an ADO.NET connection. Factory for ITransaction. Holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier.

Now, suppose I have the following scenario:

I have a simple classifier which is a MSSQL table with two columns – ID (auto_increment) and Name (nvarchar). To edit this classifier I create a form which contains a single gridview and two buttons – OK and Cancel. The user can nearly directly edit the table in the gridview, and when he hits OK the changes he made are persisted to the DB (or if he hits cancel, nothing happens).

Now, I have several questions about how to organize this:

  1. What should the lifetime of my ISession be?
    Should I create a single ISession for my whole application; an ISession for each of my forms (the application is single-threaded MDI); or an ISession for every DB operation/transaction?
  2. Does NHibernate offer some kind of built-in dirty tracking or must I do this myself? The manual mentions something like it here and there but does not go into details.
    1. How is this done?
    2. Is there not a huge overhead?
    3. Is it somehow tied with the cache(s) that NHibernate has?
    4. What are these caches for?
    5. Are they not specific to a single ISession? That is, if I use a seperate ISession for every transaction, won’t it break the dirty tracking?
    6. How does the built-in dirty tracking detect deleted objects?
  • 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-13T22:10:01+00:00Added an answer on May 13, 2026 at 10:10 pm

    What should the lifetime of my ISession be?

    Several questions address this:

    • What should be the lifetime of an NHibernate session?
    • NHibernate sessions: How many? When to create? When to close?

    Does NHibernate offer some kind of built-in dirty tracking or must I do this myself?

    NHibernate has built-in dirty tracking.

    How is this done?

    In a nutshell, an EntityEntry keeps the state of the entity when it is loaded, then when the session is flushed this loaded state is compared to the actual state. Fields/properties with differing values are marked as dirty. It’s actually much more complex than this, but as a user you don’t need to know exactly how it works.

    Is there not a huge overhead?

    No. It’s only a concern if you’re managing a huge amount of entities in a single session (something you shouldn’t do anyway)

    Is it somehow tied with the cache(s) that NHibernate has?

    What are these caches for?

    Are they not specific to a single ISession? That is, if I use a seperate ISession for every transaction, won’t it break the dirty tracking?

    How does the built-in dirty tracking detect deleted objects?

    It seems that you’re confusing dirty tracking, caching and concurrency. Caching and concurrency are highly configurable, these articles explain them very well:

    • http://ayende.com/Blog/archive/2009/04/15/nhibernate-mapping-concurrency.aspx
    • http://ayende.com/Blog/archive/2008/01/24/NHibernate-and-the-second-level-cache-tips.aspx

    Dirty tracking behavior can be overriden as well, but the default behavior is appropriate for 99% of the cases.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

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.