Example #1
0
 public IList <T> Buscar()
 {
     using (ISession _session = NHibernateConexao.OpenSession())
     {
         return((from rs in _session.Query <T>() select rs).ToList());
     }
 }
Example #2
0
 public T Buscar(int id)
 {
     using (ISession _session = NHibernateConexao.OpenSession())
     {
         return(_session.Get <T>(id));
     }
 }
Example #3
0
 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);
                 }
             }
         }
     }
 }