59909a5ee7
Must use the Repositories with Using or else bad things will happen.
53 lines
1.4 KiB
C#
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
|
|
}
|
|
}
|