public IList ExecuteSQLQuery(string sql) {
            ITransaction trn = this._session.BeginTransaction();
            try {
                ISQLQuery sqlQuery = _session.CreateSQLQuery(sql);

                int ss = sql.IndexOf(" ");
                sql = sql.Substring(ss + 1);
                int ee = sql.IndexOf(" from");
                sql = sql.Substring(0, ee);
                string[] filed = sql.Split(new char[] { ',' });
                for (int i = 0; i < filed.Length; i++) {
                    if (filed[i].IndexOf("as") > 0) {
                        filed[i] = filed[i].Substring(filed[i].IndexOf("as") + 3).Trim();
                    }
                    sqlQuery.AddScalar(filed[i], NHibernateUtil.String);
                }
                IList resultList = sqlQuery.List();
                trn.Commit();
                return resultList;
            } catch (Exception e) {
                trn.Rollback();
                throw e;
            }
        }


注意,此方法 的SQLSTR最好 字段和表明 都用别名,例如:select t1.filed1 as filed1,t1.field2 as field2 from table1 as t1 where t1.filed2>0;

相关文章:

  • 2021-06-30
  • 2021-08-01
  • 2021-04-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-31
  • 2022-12-23
  • 2021-06-23
  • 2021-09-18
  • 2021-10-19
  • 2021-12-19
  • 2022-12-23
相关资源
相似解决方案