public override IAsyncEnumerable <Object> Execute(Object dataContext, OeQueryContext queryContext) { Expression expression; MethodCallExpression countExpression = null; IQueryable query = queryContext.EntitySetAdapter.GetEntitySet(dataContext); if (base.QueryCache.AllowCache) { expression = GetFromCache(queryContext, (T)dataContext, base.QueryCache, out countExpression); } else { expression = queryContext.CreateExpression(new OeConstantToVariableVisitor()); expression = new OeEf6EnumerableToQuerableVisitor().Visit(expression); expression = queryContext.TranslateSource(dataContext, expression); if (queryContext.IsQueryCount()) { countExpression = queryContext.CreateCountExpression(expression); } } IDbAsyncEnumerable asyncEnumerable = (IDbAsyncEnumerable)query.Provider.CreateQuery(expression); IAsyncEnumerable <Object> asyncEnumerator = new OeEf6AsyncEnumerator(asyncEnumerable); if (countExpression != null) { query = queryContext.EntitySetAdapter.GetEntitySet(dataContext); queryContext.TotalCountOfItems = query.Provider.Execute <int>(countExpression); } return(asyncEnumerator); }
public override Db.OeAsyncEnumerator ExecuteEnumerator(Object dataContext, OeQueryContext queryContext, CancellationToken cancellationToken) { Expression expression; MethodCallExpression countExpression = null; IQueryable query = queryContext.EntitySetAdapter.GetEntitySet(dataContext); if (base.QueryCache.AllowCache) { expression = GetFromCache(queryContext, (T)dataContext, base.QueryCache, out countExpression); } else { expression = queryContext.CreateExpression(new OeConstantToVariableVisitor()); expression = new OeEf6EnumerableToQuerableVisitor().Visit(expression); expression = queryContext.TranslateSource(dataContext, expression); if (queryContext.ODataUri.QueryCount.GetValueOrDefault()) { countExpression = OeQueryContext.CreateCountExpression(expression); } } IDbAsyncEnumerable asyncEnumerable = (IDbAsyncEnumerable)query.Provider.CreateQuery(expression); Db.OeAsyncEnumerator asyncEnumerator = new OeEf6AsyncEnumerator(asyncEnumerable.GetAsyncEnumerator(), cancellationToken); if (countExpression != null) { query = queryContext.EntitySetAdapter.GetEntitySet(dataContext); asyncEnumerator.Count = query.Provider.Execute <int>(countExpression); } return(asyncEnumerator); }
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); }
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 OeEf6EnumerableToQuerableVisitor().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); }