0

I am trying to write a single LINQ query to compute aggregates like sum/average/min/max and count. In my app, user selects the aggregate, which will be sent from the UI and stored in a variable. How can I use aggregate dynamically in LINQ query?

Sample query:

 var selectedAggregate ="Count";

 var xaxisparam2 = (from b in FiltersList
                  where (--column name--)
                 group b by (--column name--) into c
                  select new
                      {
                         XaxisVal = c.Key,
                         AggreMeasure = c.Average(--column name --),
                     }).ToList();

AggreMeasure = c.Average(--column name --), In this line in place of "Average", user selected aggregate has to be used dynamically.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Raushan Rauf
  • 45
  • 10
  • 1
    Possible duplicate of [How to make aggregate function in single method using linq?](https://stackoverflow.com/questions/37371586/how-to-make-aggregate-function-in-single-method-using-linq) See also [Dynamic LINQ aggregates on IQueryable as a single query](https://stackoverflow.com/q/21634630/215552). – Heretic Monkey May 20 '19 at 19:12
  • is it possible to use directly similar to dynamic property passing as a column? – Raushan Rauf May 22 '19 at 10:54

0 Answers0