I have
var query = from c in db.customers_info
group c by c.issue_date into g
select new
{
name = g.Key,
value = g.Count()
};
Instead of grouping by c.issue_date, there are other fields such as 'c.gender', 'c.termination_date', 'c.customer_name' and many many fields. I'd like to create a console app where user can input a string of what he want to group by, and the query will pick it up. Something like
var query = from c in db.customers_info
group c by c.{user_input} into g
select new
{
name = g.Key,
value = g.Count()
};
My suboptimal solution so far:
var query = from c in db.customers_info
group c by user_input.Equals("issue_date")? c.issue_date : user_input.Equals("gender")? c.gender : ... and more conditions.
into g
select new
{
name = g.Key,
value = g.Count()
};
Is it possible?
EDIT: would prefer to process groupby as part of the generated SQL query, rather than bringing all fields into the app, and groupby in app level. Thanks!