예제 #1
0
        private static Expression BuildSqlCompatibleExpression(Expression expression, out IQueryable source)
        {
            bool pullIntoMemory = ShouldBePulledIntoMemory(expression);

            var handleInProviderVisitor = new DataFacadeQueryableExpressionVisitor(pullIntoMemory);

            var newExpression = handleInProviderVisitor.Visit(expression);

            // Checking if the source contains queries both from SQL and Composite.Data.Caching.CachingQueryable in-memory queries.
            // In this case, we can replace CachingQueryable instances with sql queries which allows building correct sql statements.
            var analyzer = new QueryableAnalyzerVisitor();

            analyzer.Visit(newExpression);

            if (analyzer.CachedSqlQueries > 1 ||
                (analyzer.SqlQueries > 0 && analyzer.CachedSqlQueries > 0))
            {
                newExpression = new CachedQueryExtractorVisitor().Visit(newExpression);
                newExpression = handleInProviderVisitor.Visit(newExpression);
            }

            source = handleInProviderVisitor.Queryable;

            return(newExpression);
        }
예제 #2
0
        public S Execute <S>(Expression expression)
        {
            bool pullIntoMemory = ShouldBePulledIntoMemory(expression);

            var handleInProviderVisitor = new DataFacadeQueryableExpressionVisitor(pullIntoMemory);

            Expression newExpression = handleInProviderVisitor.Visit(expression);

            IQueryable source = handleInProviderVisitor.Queryable;

            return((S)source.Provider.Execute(newExpression));
        }
예제 #3
0
        public IEnumerator <T> GetEnumerator()
        {
            if (object.Equals(_currentExpression, _initialExpression))
            {
                if (_sources.Count == 1 && _sources[0] is IEnumerable <T> )
                {
                    return((_sources[0] as IEnumerable <T>).GetEnumerator());
                }

                if (_sources.Count == 0)
                {
                    return(new List <T>().GetEnumerator());
                }
            }

            bool pullIntoMemory          = ShouldBePulledIntoMemory(_currentExpression);
            var  handleInProviderVisitor = new DataFacadeQueryableExpressionVisitor(pullIntoMemory);

            Expression newExpression = handleInProviderVisitor.Visit(_currentExpression);

            // Checking if the source contains queries both from SQL and Composite.Data.Caching.CachingQueryable in-memory queries.
            // In this case, we can replace CachingQueryable instances with sql queries which allows building correct sql statements.
            var analyzer = new QueryableAnalyzerVisitor();

            analyzer.Visit(newExpression);

            if (analyzer.CachedSqlQueries > 1 ||
                (analyzer.SqlQueries > 0 && analyzer.CachedSqlQueries > 0))
            {
                newExpression = new CachedQueryExtractorVisitor().Visit(newExpression);
                newExpression = handleInProviderVisitor.Visit(newExpression);
            }

            // Executing the query
            IQueryable     source    = handleInProviderVisitor.Queryable;
            IQueryable <T> queryable = (IQueryable <T>)source.Provider.CreateQuery(newExpression);

            return(queryable.GetEnumerator());
        }