/// <Create> /// 通过传入Food对象,创建Food写进数据库 /// </Create> /// <param name="foodInfo"></param> /// <returns></returns> public int CreateFood(Food foodInfo) { using (ITransaction tx = Session.BeginTransaction()) { try { int newid = (int)Session.Save(foodInfo); Session.Flush(); tx.Commit(); return newid; } catch (HibernateException) { tx.Rollback(); throw; } } }
/// <summary> /// 更新Food /// </summary> /// <param name="foodInfo"></param> /// <returns></returns> public void UpdateFood(Food foodInfo) { using (ITransaction tx = Session.BeginTransaction()) { try { Session.Update(foodInfo); Session.Flush(); tx.Commit(); } catch (HibernateException) { tx.Rollback(); throw; } } }