Nhibernate configuaration in Asp.net (urgent)
Hi all,In my web application Nhibernate configuration done and able to create persistence sessions.
But problem occurs when perform set of transactions. Current session is closed with next transaction. Therefore multiple transactions couldn't be performed.
Source Code
01 Variables
private static Configuration myConfiguration;
private static ISessionFactory _sessionFactory;
private static ISession _persistentSession;
02 Getter for Session Factory attribute
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
if (_sessionFactory == null)
{
//var configuration = new NHibernate.Cfg.Configuration();
myConfiguration = new NHibernate.Cfg.Configuration();
myConfiguration.Configure();
_sessionFactory = myConfiguration.BuildSessionFactory();
}
}
return _sessionFactory;
}
}
03 Return Persistence session
public static ISession GetPersistentSession()
{
if (_persistentSession == null)
{
_persistentSession = SessionFactory.OpenSession();
}
if (_persistentSession.IsOpen == false)
{
_persistentSession.Dispose();
_persistentSession = SessionFactory.OpenSession();
}
return _persistentSession;
}
04 usage of Persistence session
public bool SaveVoucher(Voucher v, string user, string docType)
{
using (ISession session = GetPersistentSession())
{
try
{
using (session.BeginTransaction())
{
Within above session.BeginTransaction() different transactions from same module or other modules are called. Then current session is closed.
Any Solution
Thanks