public DataSourceLoaderImpl(IQueryable <S> source, DataSourceLoadOptionsBase options, CancellationToken cancellationToken, bool sync)
        {
            var providerInfo = new QueryProviderInfo(source.Provider);
            var guardNulls   = providerInfo.IsLinqToObjects;

            if (!sync)
            {
                AsyncHelper = new AsyncHelper(source.Provider, providerInfo, cancellationToken);
            }

#if DEBUG
            ExpressionWatcher = options.ExpressionWatcher;
            UseEnumerableOnce = options.UseEnumerableOnce;
            guardNulls        = guardNulls && !options.SuppressGuardNulls;
#endif

            Source  = source;
            Context = new DataSourceLoadContext(options, providerInfo, typeof(S));
            Builder = new DataSourceExpressionBuilder <S>(
                Context,
                guardNulls,
                new AnonTypeNewTweaks {
                AllowEmpty         = !providerInfo.IsL2S,
                AllowUnusedMembers = !providerInfo.IsL2S
            }
                );
        }
Esempio n. 2
0
        public object Load <T>(IEnumerable <T> source, DataSourceLoadOptions options)
        {
            var builder = new DataSourceExpressionBuilder <T> {
                Skip   = options.Skip,
                Take   = options.Take,
                Filter = options.Filter,
                Sort   = options.Sort
            };

            var q = source.AsQueryable();

            if (options.IsCountQuery)
            {
                return(builder.Build(true).Compile().DynamicInvoke(q));
            }

            var data = builder.Build(false).Compile().DynamicInvoke(q);

            if (options.RequireTotalCount)
            {
                return new Dictionary <string, object> {
                           { "data", data },
                           { "totalCount", builder.Build(true).Compile().DynamicInvoke(q) }
                }
            }
            ;

            return(data);
        }
    }
 static RemoteGroupingResult ExecRemoteGrouping <T>(IQueryable <T> source, DataSourceExpressionBuilder <T> builder, DataSourceLoadOptionsBase options)
 {
     return(RemoteGroupTransformer.Run(
                ExecQuery(builder.BuildLoadGroupsExpr().Compile(), source, options),
                options.HasGroups ? options.Group.Length : 0,
                options.TotalSummary,
                options.GroupSummary
                ));
 }
        public DataSourceLoaderImpl(IQueryable <S> source, DataSourceLoadOptionsBase options)
        {
            QueryProviderInfo       = new QueryProviderInfo(source.Provider);
            Builder                 = new DataSourceExpressionBuilder <S>(options, QueryProviderInfo.IsLinqToObjects);
            ShouldEmptyGroups       = options.HasGroups && !options.Group.Last().GetIsExpanded();
            CanUseRemoteGrouping    = options.RemoteGrouping ?? ShouldUseRemoteGrouping(QueryProviderInfo, options);
            SummaryIsTotalCountOnly = !options.HasGroupSummary && options.HasSummary && options.TotalSummary.All(i => i.SummaryType == AggregateName.COUNT);

            Source  = source;
            Options = options;
        }
        public DataSourceLoaderImpl(IQueryable<S> source, DataSourceLoadOptionsBase options) {
            var isLinqToObjects = source is EnumerableQuery;

            // Until https://github.com/aspnet/EntityFramework/issues/2341 is implemented
            // local grouping is more efficient for EF Core
            var preferLocalGrouping = Compat.IsEFCore(source.Provider);

            Builder = new DataSourceExpressionBuilder<S>(options, isLinqToObjects);
            ShouldEmptyGroups = options.HasGroups && !options.Group.Last().GetIsExpanded();
            CanUseRemoteGrouping = options.RemoteGrouping ?? !(isLinqToObjects || preferLocalGrouping);
            SummaryIsTotalCountOnly = !options.HasGroupSummary && options.HasSummary && options.TotalSummary.All(i => i.SummaryType == AggregateName.COUNT);

            Source = source;
            Options = options;
        }
Esempio n. 6
0
        public DataSourceLoaderImpl(IQueryable <S> source, DataSourceLoadOptionsBase options)
        {
            QueryProviderInfo = new QueryProviderInfo(source.Provider);
            Builder           = new DataSourceExpressionBuilder <S>(
                options,
                QueryProviderInfo.IsLinqToObjects,
                options.StringToLower.GetValueOrDefault(QueryProviderInfo.IsLinqToObjects),
                new AnonTypeNewTweaks {
                AllowEmpty         = !QueryProviderInfo.IsL2S,
                AllowUnusedMembers = !QueryProviderInfo.IsL2S
            }
                );
            ShouldEmptyGroups       = options.HasGroups && !options.Group.Last().GetIsExpanded();
            CanUseRemoteGrouping    = options.RemoteGrouping ?? ShouldUseRemoteGrouping(QueryProviderInfo, options);
            SummaryIsTotalCountOnly = !options.HasGroupSummary && options.HasSummary && options.TotalSummary.All(i => i.SummaryType == AggregateName.COUNT);

            Source  = source;
            Options = options;
        }
        public DataSourceLoaderImpl(IQueryable <S> source, DataSourceLoadOptionsBase options)
        {
#if DEBUG
            ExpressionWatcher = options.ExpressionWatcher;
            UseEnumerableOnce = options.UseEnumerableOnce;
#endif

            var providerInfo = new QueryProviderInfo(source.Provider);

            Source  = source;
            Context = new DataSourceLoadContext(options, providerInfo, typeof(S));
            Builder = new DataSourceExpressionBuilder <S>(
                Context,
                providerInfo.IsLinqToObjects,
                new AnonTypeNewTweaks {
                AllowEmpty         = !providerInfo.IsL2S,
                AllowUnusedMembers = !providerInfo.IsL2S
            }
                );
        }
        public static object Load <T>(IQueryable <T> source, DataSourceLoadOptionsBase options)
        {
            var isLinqToObjects = source is EnumerableQuery;
            var builder         = new DataSourceExpressionBuilder <T>(options, isLinqToObjects);

            if (options.IsCountQuery)
            {
                return(builder.BuildCountExpr().Compile()(source));
            }

            var accessor             = new DefaultAccessor <T>();
            var result               = new DataSourceLoadResult();
            var emptyGroups          = options.HasGroups && !options.Group.Last().GetIsExpanded();
            var canUseRemoteGrouping = options.RemoteGrouping.HasValue ? options.RemoteGrouping.Value : !isLinqToObjects;

            if (canUseRemoteGrouping && emptyGroups)
            {
                var groupingResult = ExecRemoteGrouping(source, builder, options);

                EmptyGroups(groupingResult.Groups, options.Group.Length);

                result.data       = Paginate(groupingResult.Groups, options.Skip, options.Take);
                result.summary    = groupingResult.Totals;
                result.totalCount = groupingResult.TotalCount;

                if (options.RequireGroupCount)
                {
                    result.groupCount = groupingResult.Groups.Count();
                }
            }
            else
            {
                if (!options.HasPrimaryKey)
                {
                    options.PrimaryKey = Utils.GetPrimaryKey(typeof(T));
                }

                if (!options.HasPrimaryKey && (options.Skip > 0 || options.Take > 0) && Compat.IsEntityFramework(source.Provider))
                {
                    options.DefaultSort = EFSorting.FindSortableMember(typeof(T));
                }

                var deferPaging = options.HasGroups || options.HasSummary && !canUseRemoteGrouping;
                var queryResult = ExecQuery(builder.BuildLoadExpr(!deferPaging).Compile(), source, options);

                IEnumerable data = queryResult;

                if (options.HasGroups)
                {
                    data = new GroupHelper <T>(accessor).Group(queryResult, options.Group);
                    if (options.RequireGroupCount)
                    {
                        result.groupCount = (data as IList).Count;
                    }
                }

                if (canUseRemoteGrouping && options.HasSummary && !options.HasGroups)
                {
                    var groupingResult = ExecRemoteGrouping(source, builder, options);
                    result.totalCount = groupingResult.TotalCount;
                    result.summary    = groupingResult.Totals;
                }
                else
                {
                    if (options.RequireTotalCount)
                    {
                        result.totalCount = builder.BuildCountExpr().Compile()(source);
                    }

                    if (options.HasSummary)
                    {
                        data           = Buffer <T>(data);
                        result.summary = new AggregateCalculator <T>(data, accessor, options.TotalSummary, options.GroupSummary).Run();
                    }
                }

                if (deferPaging)
                {
                    data = Paginate(data, options.Skip, options.Take);
                }

                if (emptyGroups)
                {
                    EmptyGroups(data, options.Group.Length);
                }

                result.data = data;
            }

            if (result.IsDataOnly())
            {
                return(result.data);
            }

            return(result);
        }