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?