Пример #1
0
        // Executes a query with a scalar result, i.e. a query that ends with a result operator such as Count, Sum, or Average.
        public T ExecuteScalar <T>(QueryModel queryModel)
        {
            var visitor = new QueryVisitor(_collectionName, _collectionSchema);

            visitor.VisitQueryModel(queryModel);

            var expression = visitor.RootExpression;

            _customAction?.Invoke(expression);

            Dbg.Trace($"linq provider produced expression {expression}");

            if (expression.CountOnly)
            {
                return((T)(object)_client.EvalQuery(expression).Item2);
            }

            throw new NotSupportedException("Only Count scalar method is implemented");
        }
Пример #2
0
        internal override IDataClient TryExecute(IDataClient client)
        {
            if (!CanExecute)
            {
                return(client);
            }

            Dbg.CheckThat(Params.Count == 2 || Params.Count == 1);

            var result = new Tuple <bool, int>(false, 0);

            try
            {
                Dbg.CheckThat(Query != null);

                Profiler.IsActive = true;
                Profiler.Start("COUNT");

                result = client.EvalQuery(Query);
            }
            catch (CacheException ex)
            {
                Logger.WriteEror("Can not execute COUNT : {0} {1}", ex.Message, ex.ServerMessage);
            }
            catch (Exception ex)
            {
                Logger.WriteEror("Can not execute COUNT : {0}", ex.Message);
                return(client);
            }
            finally
            {
                Profiler.End();

                Logger.Write("Found {0} items. The call took {1:F4} miliseconds", result.Item2,
                             Profiler.TotalTimeMilliseconds);
            }


            return(client);
        }
Пример #3
0
        public static bool IsComplete <T>(this IDataClient @this, Expression <Func <T, bool> > where)
        {
            var query = PredicateToQuery(where);

            return(@this.EvalQuery(query).Item1);
        }
Пример #4
0
        public static int Count <T>(this IDataClient @this, Expression <Func <T, bool> > where)
        {
            var query = PredicateToQuery(where);

            return(@this.EvalQuery(query).Item2);
        }