public T GetById(int id) { using (ISession Session = SessionFactoryBuilder.getConnection()) { return(Session.Get <T>(id)); } }
public IList <T> GetList() { using (ISession Session = SessionFactoryBuilder.getConnection()) { return(Session.Query <T>().ToList()); } }
public void Update(T entity) { using (ISession Session = SessionFactoryBuilder.getConnection()) { using (ITransaction transaction = Session.BeginTransaction()) { try { Session.Update(entity); transaction.Commit(); Session.Flush(); // return Session; } catch (Exception e) { if (transaction.WasCommitted) { transaction.Rollback(); } throw new SystemException("insert error: " + e.Message); } } } }
public int Add(T entity) { using (ISession Session = SessionFactoryBuilder.getConnection()) { using (ITransaction transaction = Session.BeginTransaction()) { try { int result = (int)Session.Save(entity); transaction.Commit(); Session.Flush(); return(result); } catch (Exception e) { if (transaction.WasCommitted) { transaction.Rollback(); } throw new SystemException("insert error: " + e.Message); } } } }