/// <summary> /// 通过HQL进行数据对象的查询,查询出单个数据对象 /// </summary> /// <typeparam name="T">泛型类型,由用户定义</typeparam> /// <param name="session">需要执行操作的Session</param> /// <param name="hql">需要执行的HQL查询语句</param> /// <param name="dbParamCollection">查询中的参数集合</param> /// <returns>返回查询到的数据对象</returns> public static T FindUniqueObjectByHQL <T>(ISession session, string hql, DBParamCollection dbParamCollection) { IQuery query = session.CreateQuery(hql); HibernateHelper.FillQueryParams(query, dbParamCollection); return(query.UniqueResult <T>()); }
/// <summary> /// 通过配置的SQL名称执行SQL查询 /// </summary> /// <param name="session">需要执行操作的Session</param> /// <param name="queryName">配置的查询名称</param> /// <param name="dbParamCollection">查询中的参数集合</param> /// <returns>返回查询到的数据对象集合</returns> public static IList ExecuteNameQuery(ISession session, string queryName, DBParamCollection dbParamCollection) { HibernateHelper.FlushSession(session); IQuery query = session.GetNamedQuery(queryName); HibernateHelper.FillQueryParams(query, dbParamCollection); return(query.List()); }
/// <summary> /// 通过HQL进行数据的删除 /// </summary> /// <param name="session">需要执行操作的Session</param> /// <param name="hql">需要执行的HQL的删除语句</param> /// <param name="dbParamCollection">查询中的参数集合</param> /// <returns>返回删除的结果</returns> public static int DeleteObjectByHQL(ISession session, string hql, DBParamCollection dbParamCollection) { IQuery query = session.CreateQuery(hql); HibernateHelper.FillQueryParams(query, dbParamCollection); int count = query.ExecuteUpdate(); return(count); }
/// <summary> /// 通过HQL进行数据对象的查询 /// </summary> /// <typeparam name="T">泛型类型,由用户定义</typeparam> /// <param name="session">需要执行操作的Session</param> /// <param name="hql">需要执行的HQL查询语句</param> /// <param name="dbParamCollection">查询中的参数集合</param> /// <param name="pager">分页对象</param> /// <returns>返回查询到的对象集合</returns> public static IList <T> FindObjectListByHQL <T>(ISession session, string hql, DBParamCollection dbParamCollection, Pager pager) { IQuery query = session.CreateQuery(hql); HibernateHelper.FillQueryParams(query, dbParamCollection); query.SetFirstResult(pager.StartRecord); query.SetMaxResults(pager.PageSize); return(query.List <T>()); }
/// <summary> /// 通过HQL进行数据对象的查询 /// </summary> /// <typeparam name="T">泛型类型,由用户定义</typeparam> /// <param name="session">需要执行操作的Session</param> /// <param name="hql">需要执行的HQL查询语句</param> /// <param name="dbParamCollection">查询中的参数集合</param> /// <returns>返回查询到的对象集合</returns> public static IList <T> FindObjectListByHQL <T>(ISession session, string hql, DBParamCollection dbParamCollection) { IQuery query = session.CreateQuery(hql); Console.WriteLine("Parse Params Start:" + DateTime.Now.ToString("mm:ss fff")); HibernateHelper.FillQueryParams(query, dbParamCollection); Console.WriteLine("Parse Params End:" + DateTime.Now.ToString("mm:ss fff")); return(query.List <T>()); }
/// <summary> /// 通过SQL进行数据对象的删除 /// </summary> /// <param name="session">需要执行操作的Session</param> /// <param name="sql">需要执行的SQL查询语句</param> /// <param name="dbParamCollection">查询中的参数集合</param> /// <returns>返回删除结果对象</returns> public static int DeleteObjectBySQL(ISession session, string sql, DBParamCollection dbParamCollection) { IQuery query = session.CreateSQLQuery(sql); if (dbParamCollection != null) { HibernateHelper.FillQueryParams(query, dbParamCollection); } int count = query.ExecuteUpdate(); return(count); }
/// <summary> /// 通过SQL进行数据对象的查询 /// </summary> /// <typeparam name="T">泛型类型,由用户定义</typeparam> /// <param name="session">需要执行操作的Session</param> /// <param name="sql">需要执行的SQL查询语句</param> /// <param name="dbParamCollection">查询中的参数集合</param> /// <param name="alias">需要进行填充的数据对象别名</param> /// <param name="entityClass">需要填充的数据对象类型</param> /// <param name="pager">分页对象</param> /// <returns>返回查询到的数据对象集合</returns> public static IList <T> FindObjectListBySQL <T>(ISession session, string sql, DBParamCollection dbParamCollection, string alias, Type entityClass, Pager pager) { IQuery query = session.CreateSQLQuery(sql).AddEntity(alias, entityClass); HibernateHelper.FillQueryParams(query, dbParamCollection); if (pager != null) { query.SetFirstResult(pager.StartRecord); query.SetMaxResults(pager.PageSize); } return(query.List <T>()); }