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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:37:01+00:00 2026-05-13T06:37:01+00:00

I am using the repository pattern in nhibernate. In a asp.net mvc application. I

  • 0

I am using the repository pattern in nhibernate.
In a asp.net mvc application.
I have a httpmodule, that:

beginRequest it calls session.beginTransaction();
EndRequest it calls session.Transaction.Commit();

This is fine for 95% of the time.

I have a case where I need to do the following in a single request:

List<User> users = factory.getUsers();

// update users

// commit transaction

// load users from the db again

Should I just call:

factory.Session.Transaction.Commit();
factory.Session.BeginTransaction();

I know this is one of the reasons against using the Repository pattern, and having the Session start/end in a HttpModule, but anyway that is how I am doing it 🙂

What are my options?

Uptate
So basically I will now have:

A page request will look like:

BeginRequest:  Session.BeginTransaction();

userlist.aspx:   
               // code to fetch users from the db
               // update users
               Session.Transaction.Commit();
               Session.BeginTransaction();
               // code to fetch recently commited users form db

EndRequest:    Session.Transaction.Commit();

Does the above seem correct?

I guess I should also first check if there is a current transaction before calling commit and begin again?

  • 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-13T06:37:01+00:00Added an answer on May 13, 2026 at 6:37 am

    You have two pieces of logic

    List<User> users = factory.getUsers();
    
    // update users
    

    and

    load users
    

    and you want those to be in separate transactions. So you add the appropriate Starts and Commits. It works, where’s the problem?

    having the Session start/end in a
    HttpModule, but anyway that is how I
    am doing it 🙂 What are my options?

    Is the point of the discussion whether to have Session start end in HttpModule? Well, your options is not to do it! You have a block of logic (admitedly here very simple logic) potentially it’s reusable so move it to its own class. Do you think it’s better to have

    client code:

      useSomeLogic() // bzzzt forgot to start session
    
      startSession()
      useSomeLogic()  // ok thank you, I can work, but please remember to commit
      commit()
    

    Or

      useSomeLogic() // just fine, I'll start the session and do you work for you and commit
    

    I like nicely packaged reusable code, and that’s why I refactor things away from transport-specific modules.

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

Sidebar

Related Questions

I have an MVC-based site, which is using a Repository/Service pattern for data access.
I'm using the repository pattern. I have a Country repository that I'm using a
I'm working on a new project and I'm using the repository pattern, I have
Simple question. How do I use UnitOfWork with Castle.Windsor, nHibernate, and ASP.NET MVC? Now
I have someone connecting to my repository using the url (substituted the IP address):
I have to delete a versioned file my bzr repository using bzr remove command.
I am using an SVN repository for my web development work. I have a
I am trying to use the repository pattern, ninject for DI with fluent nhibernate.
I am sortof using a repository pattern to extract information from a database. I
My project is currently using a svn repository which gains several hundred new revisions

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.