public AggregationResultItem(AggregationResult <T> result, T model, AggregationLevel level, Func <T, string> label, IEnumerable <AggregationResultItem <T> > subItems) { Result = result ?? throw new ArgumentNullException(nameof(result)); Model = model; Level = level; Label = label?.Invoke(Model); if (subItems != null) { List <AggregationResultItem <T> > list = new List <AggregationResultItem <T> >(); foreach (var subitem in subItems) { if (subitem.Parent != null) { throw new InvalidOperationException("Sub item belongs to another item."); } subitem.Parent = this; Depth = subitem.IncreaseDepth(); list.Add(subitem); } SubItems = list; } else { SubItems = new List <AggregationResultItem <T> >(5); } }
private static AggregationResult <T> Create(IEnumerable <T> models, Func <T, string> label, IEnumerable <FunctionMapping> functions) { AggregationResult <T> view = new AggregationResult <T> { _functions = functions.Select(o => FromSourceMapping(o)).ToArray() }; foreach (var model in models) { var item = new AggregationResultItem <T>(view, model, AggregationLevel.Details, label, null); view._items.Add(item); } view.AppendGeneration(); return(view); }
public AggregationResult <TResult> ToResult(IQueryable <TSource> query, Func <TResult, string> label) { return(AggregationResult <TResult> .Create(query, this, label)); }