コード例 #1
0
        private static IQueryable <T> Filter <T>(this IQueryable <T> queryable, GetRowsParams getRowsParams)
        {
            foreach (var kvp in getRowsParams.FilterModel)
            {
                var colId       = kvp.Key;
                var filterModel = kvp.Value;

                if (string.IsNullOrEmpty(filterModel.Operator))
                {
                    var predicate = GetPredicate(colId, filterModel, 0);
                    var args      = GetWhereArgs(filterModel);

                    queryable = queryable.Where(predicate, args: args);
                }
                else
                {
                    var predicateLeftSide = GetPredicate(colId, filterModel.Condition1, 0);
                    var argsLeftSide      = GetWhereArgs(filterModel.Condition1);

                    var rightSideArgsIndex = filterModel.Condition1.Type == FilterModelType.InRange ? 2 : 1;

                    var predicateRightSide = GetPredicate(colId, filterModel.Condition2, rightSideArgsIndex);
                    var argsRightSide      = GetWhereArgs(filterModel.Condition2);

                    var predicate = $"{predicateLeftSide} {filterModel.Operator} {predicateRightSide}";
                    var args      = argsLeftSide.Concat(argsRightSide).ToArray();

                    queryable = queryable.Where(predicate, args: args);
                }
            }

            return(queryable);
        }
コード例 #2
0
        public static InfiniteRowModelResult <T> GetInfiniteRowModelBlock <T>(this IQueryable <T> queryable, GetRowsParams getRowsParams)
        {
            var takeCount = getRowsParams.EndRow - getRowsParams.StartRow;

            var rows = queryable
                       .Filter(getRowsParams)
                       .Sort(getRowsParams)
                       .Skip(getRowsParams.StartRow)
                       .Take(takeCount + 1)
                       .ToList();

            var reachedEnd = rows.Count <= takeCount;

            return(new InfiniteRowModelResult <T>
            {
                RowsThisBlock = rows.Take(takeCount).ToList(),
                LastRow = reachedEnd ? getRowsParams.StartRow + rows.Count : null
            });
        }