public IList <T> Buscar() { using (ISession _session = NHibernateConexao.OpenSession()) { return((from rs in _session.Query <T>() select rs).ToList()); } }
public T Buscar(int id) { using (ISession _session = NHibernateConexao.OpenSession()) { return(_session.Get <T>(id)); } }
public void Inserir(T entidade) { using (ISession _session = NHibernateConexao.OpenSession()) { using (ITransaction _transaction = _session.BeginTransaction()) { try { _session.Save(entidade); _transaction.Commit(); } catch (Exception ex) { if (!_transaction.WasCommitted) { _transaction.Rollback(); throw new Exception("Erro ao salvar: " + ex.Message); } } } } }