Beispiel #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(_typeDescription);

            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).Value);
            }

            throw new NotSupportedException("Only Count scalar method is implemented");
        }
Beispiel #2
0
        internal override ICacheClient TryExecute(ICacheClient client)
        {
            if (!CanExecute)
            {
                return(client);
            }

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

            var result = new KeyValuePair <bool, int>();

            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
            {
                var profilerResult = Profiler.End();


                Logger.Write("Found {0} items. The call took {1:F4} miliseconds", result.Value,
                             profilerResult.TotalTimeMiliseconds);
            }


            return(client);
        }