Пример #1
0
 public T GetById(int id)
 {
     using (ISession Session = SessionFactoryBuilder.getConnection())
     {
         return(Session.Get <T>(id));
     }
 }
Пример #2
0
 public IList <T> GetList()
 {
     using (ISession Session = SessionFactoryBuilder.getConnection())
     {
         return(Session.Query <T>().ToList());
     }
 }
Пример #3
0
 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);
             }
         }
     }
 }
Пример #4
0
 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);
             }
         }
     }
 }