Example #1
0
 /// <Delete>
 /// 通过User删除数据库中的项
 /// </Delete>
 public void DeleteUser(User user)
 {
     using (ITransaction tx = Session.BeginTransaction())
     {
         try
         {
             Session.Delete(user);
             Session.Flush();
             tx.Commit();
         }
         catch (HibernateException)
         {
             tx.Rollback();
             throw;
         }
     }
 }
Example #2
0
 /// <Create>
 /// 通过传入User对象,创建User写进数据库
 /// </Create>
 public int CreateUser(User userInfo)
 {
     using (ITransaction tx = Session.BeginTransaction())
     {
         try
         {
             int newid = (int)Session.Save(userInfo);
             Session.Flush();
             tx.Commit();
             return newid;
         }
         catch (HibernateException)
         {
             tx.Rollback();
             return -1;
             throw;
         }
     }
 }