/// <summary> /// Ejecuta una instruccion SQL nativa mediante una nueva session /// </summary> /// <param name="query"></param> public void SQLNativeExecute(string query) { ISession sess = null; ITransaction trans = null; try { sess = SFactory.OpenSession(); trans = sess.BeginTransaction(); IDbCommand command = sess.Connection.CreateCommand(); command.CommandText = query; command.ExecuteNonQuery(); trans.Commit(); } catch (Exception ex) { if (trans != null) { trans.Rollback(); } throw new Exception(ex.Message); } finally { sess.Close(); } }
public IList HQLSelect(string query) { ISession sess = SFactory.OpenSession(); ITransaction trans = sess.BeginTransaction(); IList results; try { results = sess.CreateQuery(query).List(); trans.Commit(); } catch (Exception ex) { if (trans != null) { trans.Rollback(); } throw new Exception(ex.Message); } finally { sess.Close(); } return(results); }
/// <summary> /// Abre una sesión /// </summary> /// <returns>Código de session</returns> /// public int OpenSession() { int pos = 0; ISession sess = SFactory.OpenSession(); // Buscamos la primera posicion vacía foreach (ISession session in Sessions) { if (session == null) { Sessions.RemoveAt(pos); break; } pos++; } Sessions.Insert(pos, sess); return(pos); }
/*public IList SQLNativeSelect(string query, Type type) * { * ISession sess = SFactory.OpenSession(); * ITransaction trans = sess.BeginTransaction(); * IList results = null; * * try * { * IQuery nHQ = sess.CreateSQLQuery(query) * .SetResultTransformer(Transformers.AliasToBean(type)); * * results = nHQ.List(); * * trans.Commit(); * } * catch (Exception ex) * { * if (trans != null) trans.Rollback(); * throw new Exception(ex.Message); * } * finally * { * sess.Close(); * } * * return results; * }*/ /// <summary> /// Ejecuta una consulta SQL nativa mediante una nueva session /// </summary> /// <param name="query"></param> public IDataReader SQLNativeSelect(string query) { ISession sess = null; ITransaction trans = null; //System.Object values; try { sess = SFactory.OpenSession(); trans = sess.BeginTransaction(); IDbCommand command = sess.Connection.CreateCommand(); command.CommandText = query; IDataReader list = command.ExecuteReader(); trans.Commit(); //IDataRecord rec; //rec.GetValues(values); return(list); } catch (Exception ex) { if (trans != null) { trans.Rollback(); } throw ex; } finally { sess.Close(); } }
public void HQLExecute(string query, Type type) { ISession sess = SFactory.OpenSession(); ITransaction trans = sess.BeginTransaction(); try { IQuery nHQ = sess.CreateSQLQuery(query).AddEntity(type); nHQ.UniqueResult(); trans.Commit(); } catch (Exception ex) { if (trans != null) { trans.Rollback(); } throw new Exception(ex.Message); } finally { sess.Close(); } }