예제 #1
0
        private IQueryHandler <T> tryFindSingleQuery <T>(QueryModel model, IIncludeJoin[] joins, QueryStatistics stats)
        {
            var choice = model.FindOperators <ChoiceResultOperatorBase>().FirstOrDefault();

            if (choice == null)
            {
                return(null);
            }

            var query = new LinqQuery <T>(_store, model, joins, stats);

            if (choice is FirstResultOperator)
            {
                return(choice.ReturnDefaultWhenEmpty
                    ? OneResultHandler <T> .FirstOrDefault(query)
                    : OneResultHandler <T> .First(query));
            }

            if (choice is SingleResultOperator)
            {
                return(choice.ReturnDefaultWhenEmpty
                    ? OneResultHandler <T> .SingleOrDefault(query)
                    : OneResultHandler <T> .Single(query));
            }

            if (choice is MinResultOperator)
            {
                return(AggregateQueryHandler <T> .Min(query));
            }

            if (choice is MaxResultOperator)
            {
                return(AggregateQueryHandler <T> .Max(query));
            }

            if (model.HasOperator <LastResultOperator>())
            {
                throw new InvalidOperationException(
                          "Marten does not support Last()/LastOrDefault(). Use reverse ordering and First()/FirstOrDefault() instead");
            }
            return(null);
        }
예제 #2
0
        private IQueryHandler <T> tryFindScalarQuery <T>(QueryModel model)
        {
            if (model.HasOperator <CountResultOperator>() || model.HasOperator <LongCountResultOperator>())
            {
                return(new CountQueryHandler <T>(model, _schema));
            }

            if (model.HasOperator <SumResultOperator>())
            {
                return(AggregateQueryHandler <T> .Sum(_schema, model));
            }

            if (model.HasOperator <AverageResultOperator>())
            {
                return(AggregateQueryHandler <T> .Average(_schema, model));
            }

            if (model.HasOperator <AnyResultOperator>())
            {
                return(new AnyQueryHandler(model, _schema).As <IQueryHandler <T> >());
            }

            return(null);
        }
예제 #3
0
        private IQueryHandler <T> tryFindScalarQuery <T>(QueryModel model, IIncludeJoin[] joins, QueryStatistics stats)
        {
            if (model.HasOperator <CountResultOperator>() || model.HasOperator <LongCountResultOperator>())
            {
                return(new LinqQuery <T>(_store, model, joins, stats).ToCount <T>());
            }

            if (model.HasOperator <SumResultOperator>())
            {
                return(AggregateQueryHandler <T> .Sum(new LinqQuery <T>(_store, model, joins, stats)));
            }

            if (model.HasOperator <AverageResultOperator>())
            {
                return(AggregateQueryHandler <T> .Average(new LinqQuery <T>(_store, model, joins, stats)));
            }

            if (model.HasOperator <AnyResultOperator>())
            {
                return(new LinqQuery <T>(_store, model, joins, stats).ToAny().As <IQueryHandler <T> >());
            }

            return(null);
        }