narsil/Tanshu.Accounts.Repository/BusinessLayer/FluentBasicBaseBI.cs
unknown 59909a5ee7 Updated NH, Code Refactoring, made all DB transactions atomic.
Must use the Repositories with Using or else bad things will happen.
2011-06-30 01:57:07 +05:30

53 lines
1.4 KiB
C#

using System;
using NHibernate;
namespace Tanshu.Accounts.Repository
{
public class FluentBasicBase : IDisposable
{
protected readonly bool DisposeSession;
protected readonly ISession Session;
protected readonly ITransaction Transaction;
public FluentBasicBase()
{
Session = SessionManager.Session;
DisposeSession = true;
Transaction = Session.BeginTransaction();
}
public FluentBasicBase(bool beginTransaction)
{
Session = SessionManager.Session;
DisposeSession = true;
if (beginTransaction)
Transaction = Session.BeginTransaction();
}
public FluentBasicBase(ISession session)
{
this.Session = session;
DisposeSession = false;
}
public FluentBasicBase(ISession session, bool beginTransaction)
{
this.Session = session;
DisposeSession = false;
if (beginTransaction)
Transaction = Session.BeginTransaction();
}
#region IDisposable Members
public void Dispose()
{
if (Transaction != null)
{
Transaction.Commit();
Transaction.Dispose();
}
if (DisposeSession && Session != null)
Session.Dispose();
}
#endregion
}
}