Linq - Dynamic GroupBy with IEnumerable<T>
问题 I have a collection that is IEnumerable<Transaction> . Transaction has several properties such as TransactionId (Int64), PaymentMethod(string) and TransactionDate(DateTime) I'd like to be able to accomplish this transactions.GroupBy(x => x.PaymentMethod) dynamically at run time based on whatever grouping field the user has decided to use. I found most of the answer I'm looking for in dtb's answer here Linq GroupBy - how to specify the grouping key at runtime? This works well: var arg =