Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        protected IQueryable CreateQuery(OeParseUriContext parseUriContext, Object dataContext, OeConstantToVariableVisitor constantToVariableVisitor)
        {
            IQueryable query      = parseUriContext.EntitySetAdapter.GetEntitySet(dataContext);
            Expression expression = parseUriContext.CreateExpression(query, constantToVariableVisitor);

            return(query.Provider.CreateQuery(expression));
        }
Ejemplo n.º 3
0
        public override TResult ExecuteScalar <TResult>(OeParseUriContext parseUriContext, object dataContext)
        {
            IQueryable query      = parseUriContext.EntitySetAdapter.GetEntitySet(dataContext);
            Expression expression = parseUriContext.CreateExpression(query, new OeConstantToVariableVisitor());

            return(query.Provider.Execute <TResult>(expression));
        }
Ejemplo n.º 4
0
        public override OeEntityAsyncEnumerator ExecuteEnumerator(Object dataContext, OeParseUriContext parseUriContext, CancellationToken cancellationToken)
        {
            IQueryable entitySet  = parseUriContext.EntitySetAdapter.GetEntitySet(dataContext);
            Expression expression = parseUriContext.CreateExpression(entitySet, new OeConstantToVariableVisitor());

            expression = new ParameterVisitor().Visit(expression);
            var query = (IQueryable <Object>)entitySet.Provider.CreateQuery(expression);

            return(new OeEntityAsyncEnumeratorAdapter(query, cancellationToken));
        }
Ejemplo n.º 5
0
        public override Db.OeEntityAsyncEnumerator ExecuteEnumerator(OeParseUriContext parseUriContext, Object dataContext, CancellationToken cancellationToken)
        {
            IQueryable query      = parseUriContext.EntitySetAdapter.GetEntitySet(dataContext);
            Expression expression = parseUriContext.CreateExpression(query, new OeConstantToVariableVisitor());

            expression = new EnumerableToQuerableVisitor().Visit(expression);
            var queryAsync = (IDbAsyncEnumerable)query.Provider.CreateQuery(expression);

            return(new OeEf6EntityAsyncEnumerator(queryAsync.GetAsyncEnumerator(), cancellationToken));
        }
Ejemplo n.º 6
0
        public override TResult ExecuteScalar <TResult>(Object dataContext, OeParseUriContext parseUriContext)
        {
            if (base.QueryCache.AllowCache)
            {
                return(GetFromCache <TResult>(parseUriContext, (T)dataContext, base.QueryCache).Single());
            }

            IQueryable query      = parseUriContext.EntitySetAdapter.GetEntitySet(dataContext);
            Expression expression = parseUriContext.CreateExpression(query, new OeConstantToVariableVisitor());

            return(query.Provider.Execute <TResult>(expression));
        }