コード例 #1
0
        private static IEnumerable <TResult> GetFromCache <TResult>(OeParseUriContext parseUriContext, T dbContext, Db.OeQueryCache queryCache)
        {
            Db.QueryCacheItem queryCacheItem = queryCache.GetQuery(parseUriContext);

            Func <QueryContext, IEnumerable <TResult> > queryExecutor;

            if (queryCacheItem == null)
            {
                IQueryable query            = parseUriContext.EntitySetAdapter.GetEntitySet(dbContext);
                var        parameterVisitor = new OeConstantToParameterVisitor();
                Expression expression       = parseUriContext.CreateExpression(query, parameterVisitor);
                queryExecutor = dbContext.CreateQueryExecutor <TResult>(expression);

                queryCache.AddQuery(parseUriContext, queryExecutor, parameterVisitor.ConstantToParameterMapper);
                parseUriContext.ParameterValues = parameterVisitor.ParameterValues;
            }
            else
            {
                queryExecutor = (Func <QueryContext, IEnumerable <TResult> >)queryCacheItem.Query;
                parseUriContext.EntryFactory = queryCacheItem.EntryFactory;
            }

            var queryContextFactory = dbContext.GetService <IQueryContextFactory>();
            var queryContext        = queryContextFactory.Create();

            foreach (Db.OeQueryCacheDbParameterValue parameterValue in parseUriContext.ParameterValues)
            {
                queryContext.AddParameter(parameterValue.ParameterName, parameterValue.ParameterValue);
            }

            return(queryExecutor(queryContext));
        }
コード例 #2
0
        private IAsyncEnumerable <TResult> GetFromCache <TResult>(OeQueryContext queryContext, DbContext dbContext, out MethodCallExpression?countExpression)
        {
            Cache.OeCacheContext   cacheContext   = queryContext.CreateCacheContext();
            Cache.OeQueryCacheItem?queryCacheItem = base.QueryCache.GetQuery(cacheContext);

            Func <QueryContext, IAsyncEnumerable <TResult> >   queryExecutor;
            IReadOnlyList <Cache.OeQueryCacheDbParameterValue> parameterValues;

            if (queryCacheItem == null)
            {
                var        parameterVisitor = new OeConstantToParameterVisitor();
                Expression expression       = queryContext.CreateExpression(parameterVisitor);
                expression = TranslateExpression(queryContext.EdmModel, expression);
                expression = queryContext.TranslateSource(dbContext, expression);
                expression = OeEnumerableToQuerableVisitor.Translate(expression);

                queryExecutor = dbContext.CreateAsyncQueryExecutor <TResult>(expression);
                if (queryContext.EntryFactory == null)
                {
                    countExpression = null;
                }
                else
                {
                    countExpression = queryContext.CreateCountExpression(expression);
                    countExpression = (MethodCallExpression)OeEnumerableToQuerableVisitor.Translate(countExpression);
                    countExpression = (MethodCallExpression)TranslateExpression(queryContext.EdmModel, countExpression);
                }

                cacheContext = queryContext.CreateCacheContext(parameterVisitor.ConstantToParameterMapper);
                base.QueryCache.AddQuery(cacheContext, queryExecutor, countExpression, queryContext.EntryFactory);
                parameterValues = parameterVisitor.ParameterValues;
            }
            else
            {
                queryExecutor             = (Func <QueryContext, IAsyncEnumerable <TResult> >)queryCacheItem.Query;
                queryContext.EntryFactory = queryCacheItem.EntryFactory;
                countExpression           = queryCacheItem.CountExpression;
                parameterValues           = cacheContext.ParameterValues;
            }

            var          queryContextFactory = dbContext.GetService <IQueryContextFactory>();
            QueryContext efQueryContext      = queryContextFactory.Create();

            foreach (Cache.OeQueryCacheDbParameterValue parameterValue in parameterValues)
            {
                efQueryContext.AddParameter(parameterValue.ParameterName, parameterValue.ParameterValue);
            }

            if (queryContext.IsQueryCount() && countExpression != null)
            {
                countExpression = (MethodCallExpression)queryContext.TranslateSource(dbContext, countExpression);
                countExpression = (MethodCallExpression) new OeParameterToVariableVisitor().Translate(countExpression, parameterValues);
            }
            else
            {
                countExpression = null;
            }

            return(queryExecutor(efQueryContext));
        }
コード例 #3
0
        private static IAsyncEnumerable <TResult> GetFromCache <TResult>(OeQueryContext queryContext, T dbContext, Cache.OeQueryCache queryCache,
                                                                         out MethodCallExpression countExpression)
        {
            countExpression = null;
            Cache.OeCacheContext   cacheContext   = queryContext.CreateCacheContext();
            Cache.OeQueryCacheItem queryCacheItem = queryCache.GetQuery(cacheContext);

            Func <QueryContext, IAsyncEnumerable <TResult> >   queryExecutor;
            IReadOnlyList <Cache.OeQueryCacheDbParameterValue> parameterValues;
            IQueryable query = queryContext.EntitySetAdapter.GetEntitySet(dbContext);

            if (queryCacheItem == null)
            {
                var        parameterVisitor = new OeConstantToParameterVisitor();
                Expression expression       = queryContext.CreateExpression(parameterVisitor);
                expression = queryContext.TranslateSource(dbContext, expression);

                queryExecutor   = dbContext.CreateAsyncQueryExecutor <TResult>(expression);
                countExpression = OeQueryContext.CreateCountExpression(expression);
                queryCache.AddQuery(queryContext.CreateCacheContext(parameterVisitor.ConstantToParameterMapper), queryExecutor, countExpression,
                                    queryContext.EntryFactory, queryContext.SkipTokenAccessors);
                parameterValues = parameterVisitor.ParameterValues;
            }
            else
            {
                queryExecutor                   = (Func <QueryContext, IAsyncEnumerable <TResult> >)queryCacheItem.Query;
                queryContext.EntryFactory       = queryCacheItem.EntryFactory;
                queryContext.SkipTokenAccessors = queryCacheItem.SkipTokenAccessors;
                countExpression                 = queryCacheItem.CountExpression;
                parameterValues                 = cacheContext.ParameterValues;
            }

            var          queryContextFactory = dbContext.GetService <IQueryContextFactory>();
            QueryContext efQueryContext      = queryContextFactory.Create();

            foreach (Cache.OeQueryCacheDbParameterValue parameterValue in parameterValues)
            {
                efQueryContext.AddParameter(parameterValue.ParameterName, parameterValue.ParameterValue);
            }

            if (queryContext.ODataUri.QueryCount.GetValueOrDefault())
            {
                countExpression = (MethodCallExpression)queryContext.TranslateSource(dbContext, countExpression);
                countExpression = (MethodCallExpression) new OeParameterToVariableVisitor().Translate(countExpression, parameterValues);
            }
            else
            {
                countExpression = null;
            }

            return(queryExecutor(efQueryContext));
        }
コード例 #4
0
        private static Expression GetFromCache(OeQueryContext queryContext, T dbContext, Cache.OeQueryCache queryCache,
                                               out MethodCallExpression countExpression)
        {
            Cache.OeCacheContext   cacheContext   = queryContext.CreateCacheContext();
            Cache.OeQueryCacheItem queryCacheItem = queryCache.GetQuery(cacheContext);

            Expression expression;
            IReadOnlyList <Cache.OeQueryCacheDbParameterValue> parameterValues;

            if (queryCacheItem == null)
            {
                var parameterVisitor = new OeConstantToParameterVisitor();
                expression = queryContext.CreateExpression(parameterVisitor);
                expression = new OeEf6EnumerableToQuerableVisitor().Visit(expression);

                cacheContext = queryContext.CreateCacheContext(parameterVisitor.ConstantToParameterMapper);
                if (queryContext.EntryFactory == null)
                {
                    countExpression = null;
                }
                else
                {
                    countExpression = queryContext.CreateCountExpression(expression);
                }
                queryCache.AddQuery(cacheContext, expression, countExpression, queryContext.EntryFactory);
                parameterValues = parameterVisitor.ParameterValues;
            }
            else
            {
                expression = (Expression)queryCacheItem.Query;
                queryContext.EntryFactory = queryCacheItem.EntryFactory;
                countExpression           = queryCacheItem.CountExpression;
                parameterValues           = cacheContext.ParameterValues;
            }

            expression = new OeParameterToVariableVisitor().Translate(expression, parameterValues);
            expression = queryContext.TranslateSource(dbContext, expression);

            if (queryContext.IsQueryCount() && countExpression != null)
            {
                countExpression = (MethodCallExpression)queryContext.TranslateSource(dbContext, countExpression);
                countExpression = (MethodCallExpression) new OeParameterToVariableVisitor().Translate(countExpression, parameterValues);
            }
            else
            {
                countExpression = null;
            }

            return(expression);
        }
コード例 #5
0
        private static Expression GetFromCache(OeQueryContext queryContext, T dbContext, Cache.OeQueryCache queryCache,
                                               out MethodCallExpression countExpression)
        {
            Cache.OeCacheContext   cacheContext   = queryContext.CreateCacheContext();
            Cache.OeQueryCacheItem queryCacheItem = queryCache.GetQuery(cacheContext);

            Expression expression;
            IReadOnlyList <Cache.OeQueryCacheDbParameterValue> parameterValues;
            IQueryable query = queryContext.EntitySetAdapter.GetEntitySet(dbContext);

            if (queryCacheItem == null)
            {
                var parameterVisitor = new OeConstantToParameterVisitor();
                expression = queryContext.CreateExpression(parameterVisitor);
                expression = new EnumerableToQuerableVisitor().Visit(expression);

                countExpression = OeQueryContext.CreateCountExpression(expression);
                queryCache.AddQuery(queryContext.CreateCacheContext(parameterVisitor.ConstantToParameterMapper), expression, countExpression,
                                    queryContext.EntryFactory, queryContext.SkipTokenAccessors);
                parameterValues = parameterVisitor.ParameterValues;
            }
            else
            {
                expression = (Expression)queryCacheItem.Query;
                queryContext.EntryFactory       = queryCacheItem.EntryFactory;
                queryContext.SkipTokenAccessors = queryCacheItem.SkipTokenAccessors;
                countExpression = queryCacheItem.CountExpression;
                parameterValues = cacheContext.ParameterValues;
            }

            expression = new OeParameterToVariableVisitor().Translate(expression, parameterValues);
            expression = queryContext.TranslateSource(dbContext, expression);

            if (queryContext.ODataUri.QueryCount.GetValueOrDefault())
            {
                countExpression = (MethodCallExpression)queryContext.TranslateSource(dbContext, countExpression);
                countExpression = (MethodCallExpression) new OeParameterToVariableVisitor().Translate(countExpression, parameterValues);
            }
            else
            {
                countExpression = null;
            }

            return(expression);
        }
コード例 #6
0
        private static IAsyncEnumerable <TResult> GetQueryExecutor <TResult>(OeQueryContext queryContext, T dbContext)
        {
            IQueryable query = queryContext.EntitySetAdapter.GetEntitySet(dbContext);

            var        parameterVisitor = new OeConstantToParameterVisitor(queryContext.SkipTokenParser != null);
            Expression expression       = queryContext.CreateExpression(query, parameterVisitor);
            Func <QueryContext, IAsyncEnumerable <TResult> > queryExecutor = dbContext.CreateAsyncQueryExecutor <TResult>(expression);

            var          queryContextFactory = dbContext.GetService <IQueryContextFactory>();
            QueryContext efQueryContext      = queryContextFactory.Create();

            foreach (Db.OeQueryCacheDbParameterValue parameterValue in parameterVisitor.ParameterValues)
            {
                efQueryContext.AddParameter(parameterValue.ParameterName, parameterValue.ParameterValue);
            }

            if (queryContext.ODataUri.QueryCount.GetValueOrDefault())
            {
                Expression countExpression = queryContext.CreateCountExpression(query, expression);
                queryContext.CountExpression = new OeParameterToVariableVisitor().Translate(countExpression, parameterVisitor.ParameterValues);
            }

            return(queryExecutor(efQueryContext));
        }