Exemple #1
0
        private void CalculateAggregates(IEnumerable <TEntity> grouping, AggregatePropertyMetadata <TEntity> item)
        {
            if (item.AggregateFunction == AggregateFunction.Count)
            {
                var countFunction = item as CountAggregatePropertyMetadataType <TEntity>;
                _aggregateProperties[countFunction.PropertyName] = grouping.Count(t => countFunction.ParsedPropertyExpression(t));
                return;
            }

            if (item.Type == typeof(int))
            {
                var intAggr = item as AggregatePropertyMetadataType <TEntity, int>;
                CalculateAggregatesForInt(grouping, intAggr.ParsedPropertyExpression, intAggr.AggregateFunction, intAggr.PropertyName);
                return;
            }
            if (item.Type == typeof(float))
            {
                var intAggr = item as AggregatePropertyMetadataType <TEntity, float>;
                CalculateAggregatesForFloat(grouping, intAggr.ParsedPropertyExpression, intAggr.AggregateFunction, intAggr.PropertyName);
                return;
            }

            if (item.Type == typeof(long))
            {
                var intAggr = item as AggregatePropertyMetadataType <TEntity, long>;
                CalculateAggregatesForLong(grouping, intAggr.ParsedPropertyExpression, intAggr.AggregateFunction, intAggr.PropertyName);
                return;
            }
            if (item.Type == typeof(decimal))
            {
                var intAggr = item as AggregatePropertyMetadataType <TEntity, decimal>;
                CalculateAggregatesForDecimal(grouping, intAggr.ParsedPropertyExpression, intAggr.AggregateFunction, intAggr.PropertyName);
                return;
            }

            if (item.Type == typeof(double))
            {
                var intAggr = item as AggregatePropertyMetadataType <TEntity, double>;
                CalculateAggregatesForDouble(grouping, intAggr.ParsedPropertyExpression, intAggr.AggregateFunction, intAggr.PropertyName);
                return;
            }
        }
        public GroupRuleSetBuilder <TEntity, TKey> WithAggregateInfo <TType>(string propertyName, AggregateFunction function, string agrregateOn)
        {
            AggregatePropertyMetadata <TEntity> aggregatePropertyMetadata = null;

            if (function == AggregateFunction.Count)
            {
                var parser = RuleExpressionParserFactory.CreateAggregateFunctionParser <TEntity, bool>();
                aggregatePropertyMetadata = new CountAggregatePropertyMetadataType <TEntity>(_context, propertyName, typeof(TType), agrregateOn, parser);
            }
            else
            {
                var parser = RuleExpressionParserFactory.CreateAggregateFunctionParser <TEntity, TType>();
                aggregatePropertyMetadata = new AggregatePropertyMetadataType <TEntity, TType>
                                                (_context, propertyName, function, agrregateOn, parser);
            }


            _aggregateProps.Add(aggregatePropertyMetadata);
            return(this);
        }