|
using System;
using System.Collections.Generic;
using NHibernate;
using NHibernate.Criterion;
namespace ECommerceSystem.Repository
{
public class DBRepository<T>:IRepository<T>
{
public DBRepository()
{
}
void IRepository<T>.addItem(T item)
{
using (ISession session = NHibernateHelper.Create().Session)
{
using (ITransaction trans = session.BeginTransaction())
{
session.Save(item);
trans.Commit();
}
}
}
void IRepository<T>.removeItem(T item)
{
using (ISession session = NHibernateHelper.Create().Session)
{
using (ITransaction trans = session.BeginTransaction())
{
session.Delete(item);
trans.Commit();
}
}
}
void IRepository<T>.updateItem(T item)
{
using (ISession session = NHibernateHelper.Create().Session)
{
using (ITransaction trans = session.BeginTransaction())
{
session.Update(item);
trans.Commit();
}
}
}
T IRepository<T>.getItemById(long item_id)
{
T temp;
using (ISession session = NHibernateHelper.Create().Session)
{
temp = session.Get<T>(item_id);
}
return temp;
}
int IRepository<T>.getItemCount()
{
int item_count = 0;
string type_name = typeof(T).Name;
using (ISession session = NHibernateHelper.Create().Session)
{
item_count = session.CreateSQLQuery("SELECT COUNT(*) FROM "+type_name).UniqueResult<Int32>();
}
return item_count;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.