private static void ExecuteQuery(string query) { using (ISession sessao = SessionNHibernate.Criar().OpenSession()) { using (var transacao = sessao.BeginTransaction()) { sessao.CreateSQLQuery(query).ExecuteUpdate(); transacao.Commit(); } } }
public Ticket ObterPor(int id) { try { using (ISession sessao = SessionNHibernate.Criar().OpenSession()) { return(sessao.Query <Ticket>().FirstOrDefault(onde => onde.Id == id)); } } catch { throw; } }
public Ticket ObterUltimo() { try { using (ISession sessao = SessionNHibernate.Criar().OpenSession()) { return(sessao.Query <Ticket>().AsQueryable() .Where(UltimoTicket.Hoje) .OrderByDescending(ordem => ordem.DataHoraDeEntrada) .FirstOrDefault()); } } catch { throw; } }
public void Salvar(Ticket ticket) { if (ticket.Valido()) { using (ISession sessao = SessionNHibernate.Criar().OpenSession()) { using (ITransaction trasacao = sessao.BeginTransaction()) { try { sessao.SaveOrUpdate(ticket); sessao.Flush(); trasacao.Commit(); } catch { trasacao.Rollback(); throw; } } } } }