Beispiel #1
0
        /// <summary>
        /// 获取排序字符串
        /// </summary>
        /// <param name="gridParam">过滤条件</param>
        /// <param name="entityTypeFullName">实体类型名称</param>
        /// <returns></returns>
        private static string GetSort(QueryCondition gridParam, string entityTypeFullName)
        {
            string SortField = gridParam.SortField;
            string SortOrder = gridParam.SortOrder;
            string sortSQL   = string.Empty;

            if (string.IsNullOrEmpty(SortField))
            {
                sortSQL = EFTypeDescriptionCache.GetPrimaryKeyField(entityTypeFullName);
            }
            else
            {
                SortOrder = string.IsNullOrEmpty(SortOrder) ? "ASC" : SortOrder;

                //修改支持多字段排序 逗号分隔
                string[] arrSortField = SortField.Split(',');
                //判断排序方向
                string[] arrSortOrder = SortOrder.Split(',');
                for (int i = 0, length = arrSortField.Length, OrderLength = arrSortOrder.Length - 1; i < length; i++)
                {
                    sortSQL += string.Format(" {0} {1}{2}", arrSortField[i], i <= OrderLength ? arrSortOrder[i] : "asc", i < length - 1 ? "," : " ");
                }
            }
            return(sortSQL);
        }
Beispiel #2
0
        /// <summary>
        /// EF连接查询封装
        /// </summary>

        /// <typeparam name="DestinationType">目标实体类型</typeparam>
        /// <param name="Query">IQueryable对象</param>
        /// <param name="gridParam">过滤条件</param>
        /// <returns>查询结果</returns>
        public static PaginationResult <DestinationType> PageQuery <DestinationType>(this IQueryable <object> Query, QueryCondition gridParam)
        {
            if (string.IsNullOrEmpty(gridParam.SortField))
            {
                gridParam.SortField = EFTypeDescriptionCache.GetPrimaryKeyField(typeof(DestinationType).FullName);
            }
            return(Mapper.Map <PaginationResult <DestinationType> >(Query.PageQuery(gridParam)));
        }