Exemplo n.º 1
0
        /// <summary>
        /// 分布查询
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <param name="orderBy">排序条件</param>
        /// <param name="includeLogicDelete">是否包含逻辑删除数据</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageNum">页码</param>
        /// <returns></returns>
        public IList <TEntity> QueryPage(ICondition condition, OrderByGroup orderBy, bool includeLogicDelete,
                                         int pageSize, int pageNum)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition);

            if (!includeLogicDelete)
            {
                group = group.Add(isLogicDeleteCondition);
            }
            return
                (session.CreateQuery(string.Format("FROM {0} WHERE {1} ORDER BY {2}", entityType.Name, group.ToHql(),
                                                   orderBy.ToHql())).SetFirstResult((pageNum - 1) * pageSize).SetMaxResults
                     (pageSize).List <TEntity>());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 物理删除数据库中已经标记删除的数据
        /// </summary>
        /// <param name="condition"></param>
        public void PhysicalDelete(ICondition condition)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            session.CreateQuery(string.Format("DELETE FROM {0} WHERE {1}", entityType.Name, group.ToHql())).
            SetParameters(group.Parameters).ExecuteUpdate();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 按条件查询结果集
        /// </summary>
        /// <param name="condition">条件</param>
        /// <param name="orderBy">排序条件</param>
        /// <param name="includeLogicDelete">是否包含逻辑删除的数据</param>
        /// <returns>返回的结果集</returns>
        public IList <TEntity> Query(ICondition condition, OrderByGroup orderBy, bool includeLogicDelete)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition);

            if (!includeLogicDelete)
            {
                group = group.Add(isLogicDeleteCondition);
            }
            return
                (session.CreateQuery(string.Format("FROM {0} WHERE {1} ORDER BY {2}", entityType.Name, group.ToHql(),
                                                   orderBy.ToHql())).List <TEntity>());
        }
Exemplo n.º 4
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="condition">条件</param>
        /// <param name="orderBy">排序条件</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageNum">页码</param>
        /// <returns></returns>
        public IList <TEntity> QueryPage(ICondition condition, OrderByGroup orderBy, int pageSize, int pageNum)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            return
                (session.CreateQuery(string.Format("FROM  {0} where {1} Order By {2}", entityType.Name, group.ToHql(),
                                                   orderBy.ToHql())).SetParameters(group.Parameters).SetFirstResult(
                     (pageNum - 1) * pageSize).SetMaxResults(pageNum).List <TEntity>());
        }
Exemplo n.º 5
0
        /// <summary>
        /// 按条件查询结果集
        /// </summary>
        /// <param name="condition">条件</param>
        /// <returns>返回的结果集</returns>
        public IList <TEntity> Query(ICondition condition)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            return
                (session.CreateQuery(string.Format("FROM {0} WHERE {1}", entityType.Name, group.ToHql())).SetParameters(
                     group.Parameters).List <TEntity>());
        }
Exemplo n.º 6
0
        /// <summary>
        /// 得到指定条件的查询结果
        /// 如果条件可返回多条记录,则只返回第一条
        /// </summary>
        /// <param name="condition">条件</param>
        /// <returns>返回的对象</returns>
        public TEntity Get(ICondition condition)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            return
                (session.CreateQuery(string.Format("FROM {0} where {1}", entityType.Name, group.ToHql())).SetParameters(
                     group.Parameters).SetMaxResults(1).UniqueResult <TEntity>());
        }
Exemplo n.º 7
0
        /// <summary>
        /// 得到指定条件记录的数量
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <returns></returns>
        public int Count(ICondition condition)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            return
                (session.CreateQuery(string.Format("SELECT COUNT(ID) FROM {0} where {1}", entityType.Name, group.ToHql()))
                 .SetParameters(group.Parameters).UniqueResult <int>());
        }
Exemplo n.º 8
0
        /// <summary>
        /// 得到指定条件记录的数量
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public int Count(ICondition condition)
        {
            IConditionGroup cg = RepositoryHelper.ToConditionGroup(condition);

            return
                (session.CreateQuery(string.Format("Select COUNT(ID) From {0} WHERE {1}", entityType.Name, cg.ToHql())).
                 SetParameters(cg.Parameters).UniqueResult <int>());
        }