예제 #1
0
        private static ILinqQuery <TSource> Process <TSource>(
            ILinqQuery <TSource> query,
            Func <LinqQuery <TSource>, IQueryBuilderRecord> queryProcessor,
            Func <ILinqQueryInternal <TSource>, IEnumerable <TSource> > fallbackProcessor)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var candidate = query as LinqQuery <TSource>;

            if (candidate == null)
            {
                return
                    (new UnoptimizedQuery <TSource>(fallbackProcessor((ILinqQueryInternal <TSource>)EnsureLinqQuery(query))));
            }
            try
            {
                var record = queryProcessor(candidate);
                return(new LinqQuery <TSource>(candidate, record));
            }
            catch (LinqQueryException)
            {
                return(new UnoptimizedQuery <TSource>(fallbackProcessor(candidate)));
            }
        }
예제 #2
0
 public static ILinqQuery <TSource> Where <TSource>(this ILinqQuery <TSource> self,
                                                    Expression <Func <TSource, bool> > expression)
 {
     return(Process(self,
                    query => new WhereClauseVisitor().Process(expression),
                    data => data.UnoptimizedWhere(expression.Compile())
                    ));
 }
예제 #3
0
 private static ILinqQuery <TSource> ProcessOrderBy <TSource, TKey>(
     ILinqQuery <TSource> query,
     ExpressionQueryBuilder visitor,
     Expression <Func <TSource, TKey> > expression,
     Func <ILinqQueryInternal <TSource>, IEnumerable <TSource> > fallbackProcessor)
 {
     return(Process(query, q => visitor.Process(expression), fallbackProcessor));
 }
예제 #4
0
        private static ILinqQuery <TSource> EnsureLinqQuery <TSource>(ILinqQuery <TSource> query)
        {
            var placeHolderQuery = query as PlaceHolderQuery <TSource>;

            return(placeHolderQuery == null
                ? query
                : new LinqQuery <TSource>(placeHolderQuery.QueryFactory));
        }
예제 #5
0
        private IQueryable <TResultEntity> AsQueryable <TResultEntity, TEntity>(
            ILinqQuery <TResultEntity, TEntity> query)
            where TResultEntity : class
            where TEntity : class
        {
            query.DataSource = _context.Set <TEntity>();

            return(query.LinqQuery);
        }
예제 #6
0
        public static ILinqQuery <TRet> Select <TSource, TRet>(this ILinqQuery <TSource> self, Func <TSource, TRet> selector)
        {
            var placeHolderQuery = self as PlaceHolderQuery <TSource>;

            if (placeHolderQuery != null)
            {
                return(new LinqQuery <TRet>(placeHolderQuery.QueryFactory));
            }

            return(new UnoptimizedQuery <TRet>(Enumerable.Select(self, selector)));
        }
예제 #7
0
        public static int Count <TSource>(this ILinqQuery <TSource> self)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            var query = self as LinqQuery <TSource>;

            return(query != null
                ? query.Count
                : Enumerable.Count(self));
        }
예제 #8
0
        public AggregateQueryHandler(string @operator, ILinqQuery query)
        {
            _operator = @operator;
            _query    = query;

            if (typeof(T).Closes(typeof(Nullable <>)))
            {
                var typeInfo  = typeof(T).GetTypeInfo();
                var arguments = typeInfo.IsGenericTypeDefinition
                    ? typeInfo.GenericTypeParameters
                    : typeInfo.GenericTypeArguments;
                var inner = arguments.First();
                _selector = typeof(NullableScalarSelector <>).CloseAndBuildAs <ISelector <T> >(inner);
            }
            else
            {
                _selector = new ScalarSelector <T>();
            }
        }
예제 #9
0
 public static AggregateQueryHandler <T> Max(ILinqQuery query)
 {
     return(new AggregateQueryHandler <T>("max({0})", query));
 }
예제 #10
0
 public LinqQueryable(ILinqQuery <TElement> query)
 {
     _expression = Expression.Constant(this);
     _query      = query;
 }
예제 #11
0
 public AnyQueryHandler(ILinqQuery query)
 {
     _query = query;
 }
예제 #12
0
 public IQueryable <TEntity> AsQueryable <TEntity>(ILinqQuery <TEntity> query) where TEntity : class
 {
     return(AsQueryable(query as ILinqQuery <TEntity, TEntity>));
 }
예제 #13
0
 public static ILinqQuery <TSource> ThenBy <TSource, TKey>(this ILinqQuery <TSource> self,
                                                           Expression <Func <TSource, TKey> > expression)
 {
     return(ProcessOrderBy(self, new OrderByAscendingClauseVisitor(), expression,
                           data => data.UnoptimizedThenBy(expression.Compile())));
 }
예제 #14
0
 public static ILinqQueryable <TSource> AsQueryable <TSource>(this ILinqQuery <TSource> self)
 {
     return(new LinqQueryable <TSource>(self));
 }
예제 #15
0
 public static AggregateQueryHandler <T> Sum(ILinqQuery query)
 {
     return(new AggregateQueryHandler <T>("coalesce(sum({0}),0)", query));
 }
예제 #16
0
 public static AggregateQueryHandler <T> Average(ILinqQuery query)
 {
     return(new AggregateQueryHandler <T>("avg({0})", query));
 }
예제 #17
0
 public CountQueryHandler(ILinqQuery query)
 {
     _query = query;
 }