Esempio n. 1
0
        public static int?GetCount <T>(this AggregationsHelper aggs, Expression <Func <T, object> > fieldGetter, Expression <Func <T, object> > filterRule = null)
        {
            var aggName = fieldGetter.GetAggName(AggType.Count);

            if (filterRule == null)
            {
                var itemsTerms = aggs.ValueCount(aggName);
                if (!itemsTerms.Value.HasValue)
                {
                    return(null);
                }
                return((int)itemsTerms.Value);
            }
            else
            {
                var condAggName = filterRule.GenerateFilterName();
                var filterAgg   = aggs.Filter(condAggName);
                var sumAgg      = filterAgg.Sum(aggName);
                if (!sumAgg.Value.HasValue)
                {
                    return(null);
                }
                return((int)sumAgg.Value);
            }
        }