コード例 #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
ファイル: LinqQueryable.cs プロジェクト: mrdotnet/NDatabase
 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;
 }