Using a linq query, how can i pass parameters into the groupby function? Depend on user selection, it will be grouped differently
var query = (from to in OrderQuery
group to by to.FromDateUtc into groupedDate
let grouped = groupedDate.GroupBy(o => o.Name)
I would like to pass different groupby values. Any idea?
Cheers
Generally speaking, you need different queries for this. The same goes for building up different
WHEREorWhere(...)clauses based on user selection:You’ll want to prepare as much common logic as possible before you apply the grouping to
query. Because LINQ uses deferred execution you can modifyqueryas much as you need before enumerating the result and you will not incur a performance hit.