private void LoadPage(int page) { using (var tx = StatelessSession.BeginTransaction()) { var actions = StatelessSession.CreateCriteria <ToDoAction>() .SetFirstResult(page * PageSize) .SetMaxResults(PageSize) .List <ToDoAction>(); var total = StatelessSession.CreateCriteria <ToDoAction>() .SetProjection(Projections.RowCount()) .UniqueResult <int>(); this.NumberOfPages.Value = total / PageSize + (total % PageSize == 0 ? 0 : 1); this.Model = new Model { Actions = new ObservableCollection <ToDoAction>(actions), NumberOfPages = NumberOfPages, CurrentPage = CurrentPage + 1 }; this.CurrentPage.Value = page; tx.Commit(); } }
public virtual void Delete(T entity) { if (IsStatelessSession) { if (!StatelessSession.IsOpen) { throw new HibernateException("The stateless NHibernate session must be open before an entity can be deleted."); } if (StatelessSession.Transaction == null) { throw new HibernateException("Deletes must be done within an NHibernate transaction."); } StatelessSession.BeginTransaction(); StatelessSession.Delete(entity); StatelessSession.Transaction.Commit(); } else { if (!Session.IsOpen) { throw new HibernateException("NHibernate session must be open before an entity can be deleted."); } if (Session.Transaction == null) { throw new HibernateException("Deletes must be done within an NHibernate transaction."); } Session.BeginTransaction(); Session.Delete(entity); Session.Transaction.Commit(); } }