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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:49:16+00:00 2026-05-17T00:49:16+00:00

I have just converted my application from LINQ2SQL to NHibernate and I’m trying to

  • 0

I have just converted my application from LINQ2SQL to NHibernate and I’m trying to figure out how to optimise the following example. I tried using the .Future method but when my session closes the view then tries to fetch the data and I get a session closed error.

Does anyone know any best practises for this kind of thing? I have a lot of scenario’s where I call a method within LINQ which gets data using NHibernate but I don’t want to return loads of data that isn’t required.

Method to get all books:

public IEnumerable<Book>GetAllBooks()
        {
            try
            {
                using (ISession session = NHibernateHelper.OpenSession())
                {
                    return session.CreateCriteria<Widget>().ToList<Book>();
                }
            }
            catch (Exception ex)
            {
                //Error stuff here 
            }
        }

Method that then extends that functionality

        public IEnumerable<Book> GetDefaultBookReadingList()
        {
            return from p in GetAllBooks()
                   where p.IsDefault
                   select p;
        }
  • 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-17T00:49:17+00:00Added an answer on May 17, 2026 at 12:49 am

    Once you’ve closed the session (which happens at the end of your using block, you won’t be able to retrieve any lazy-loaded data.

    Depending on the application type, session management will be different, but a repository should NEVER open and close sessions.

    In web applications, the most common pattern is session-per-request.

    In windows applications, it can be conversation-per-business-transaction or, in simpler implementations, session-per-view(model)

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

Sidebar

Related Questions

I have a fairly intensive application, which I've just converted from a console application
i have just converted an app i was making from a navigation controller app
I just converted a VB.net solution into C# solution. But lots of variables have
I have a link in a cell converted to hyperlink. I looks just fine,
I've just converted my data access from Linq to SQL to Linq to Entities.
I have a website that a converted into a web application running ASP.NET webforms.
I have an application that gets terms from a DB to run as a
I have recently converted my IPad application into a Universal Application. I am re-using
Scenario : I have about 14000 word documents that need to be converted from
Simply, I'm just looking to get a list of connected remote disks. I have

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.