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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:14:07+00:00 2026-05-12T20:14:07+00:00

I am using NHibernate for my project. i am quite a beginner at working

  • 0

I am using NHibernate for my project. i am quite a beginner at working on NHibernate.

I use many-to-many relation mapping “users” and “roles”. Here is the code to get the user:

public User GetUser(int userId){
  using(ISessuib session = new SessionManager().GetSession())
  {
     return session.Get<User>(userId);
  }
}

public void LazyLoadUsingSessionTest(){
  var user= GetUser(1);
  Assert.NotNull(user.Roels);
}

it throws an exception:failed to lazily initialize a collection, no session or session was closed

if i do not use the “using” statement in the “GetUser” method,it works. But i must call the session.Close() to release the resource

when i use it in a web page,i only want to use the GetUser(), not the ISession object.so my question is : Does it mean that i must have a ISession object(to release resouse) in my web page? or any better solution?(because i do not want the ISession object appears in my aspx.cs files)

thanks!

  • 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-12T20:14:07+00:00Added an answer on May 12, 2026 at 8:14 pm

    You need to use the Session per Request pattern. See this link for an explanation of the best practices for using NHibernate with ASPX.

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

Sidebar

Related Questions

Just started developing a project using NHibernate and Fluent NHibernate for the mapping and
In my project I am using NHibernate/FluentNHibernate, and I am working with two entities,
I am using NHibernate for a project, and I am absolutely beginner. I am
I'm working on a project where we are using fluent nhibernate and perform queries
I am using Nhibernate in a project, and I am trying to run a
I have just restarted a project in which I am using NHibernate. The project
I am a Java programmer and was working on a project using Hibernate and
I am using Spring with Hibernate in my project.There are many methods written in
Hi i am using struts2 and hibernate in my project. I need to use
I have started to use NHibernate 3.0 and PostgreSQL for a small project, so

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.