Beispiel #1
0
        protected virtual IQueryable <TResource> ApplyQueryLayer(QueryLayer layer)
        {
            _traceWriter.LogMethodStart(new { layer });
            if (layer == null)
            {
                throw new ArgumentNullException(nameof(layer));
            }

            if (EntityFrameworkCoreSupport.Version.Major < 5)
            {
                var writer = new MemoryLeakDetectionBugRewriter();
                layer = writer.Rewrite(layer);
            }

            IQueryable <TResource> source = GetAll();

            var queryableHandlers = _constraintProviders
                                    .SelectMany(p => p.GetConstraints())
                                    .Where(expressionInScope => expressionInScope.Scope == null)
                                    .Select(expressionInScope => expressionInScope.Expression)
                                    .OfType <QueryableHandlerExpression>()
                                    .ToArray();

            foreach (var queryableHandler in queryableHandlers)
            {
                source = queryableHandler.Apply(source);
            }

            var nameFactory = new LambdaParameterNameFactory();
            var builder     = new QueryableBuilder(source.Expression, source.ElementType, typeof(Queryable), nameFactory, _resourceFactory, _resourceGraph, _dbContext.Model);

            var expression = builder.ApplyQuery(layer);

            return(source.Provider.CreateQuery <TResource>(expression));
        }
        protected virtual IQueryable <TResource> ApplyQueryLayer(QueryLayer layer)
        {
            _traceWriter.LogMethodStart(new
            {
                layer
            });

            ArgumentGuard.NotNull(layer, nameof(layer));

            QueryLayer rewrittenLayer = layer;

            if (EntityFrameworkCoreSupport.Version.Major < 5)
            {
                var writer = new MemoryLeakDetectionBugRewriter();
                rewrittenLayer = writer.Rewrite(layer);
            }

            IQueryable <TResource> source = GetAll();

            // @formatter:wrap_chained_method_calls chop_always
            // @formatter:keep_existing_linebreaks true

            QueryableHandlerExpression[] queryableHandlers = _constraintProviders
                                                             .SelectMany(provider => provider.GetConstraints())
                                                             .Where(expressionInScope => expressionInScope.Scope == null)
                                                             .Select(expressionInScope => expressionInScope.Expression)
                                                             .OfType <QueryableHandlerExpression>()
                                                             .ToArray();

            // @formatter:keep_existing_linebreaks restore
            // @formatter:wrap_chained_method_calls restore

            foreach (QueryableHandlerExpression queryableHandler in queryableHandlers)
            {
                source = queryableHandler.Apply(source);
            }

            var nameFactory = new LambdaParameterNameFactory();

            var builder = new QueryableBuilder(source.Expression, source.ElementType, typeof(Queryable), nameFactory, _resourceFactory, _resourceGraph,
                                               _dbContext.Model);

            Expression expression = builder.ApplyQuery(rewrittenLayer);

            return(source.Provider.CreateQuery <TResource>(expression));
        }