As I attempt to develop a LINQ groupby expression, I am utilizing Dynamic LINQ from the VS2010 code examples. I want to provide the user the option to choose the attributes to group on or by and the grouping duration at runtime (year, quarter, month). I made the decision to adopt Dynamic LINQ as a result.
A portion of my data is shown here:
Identity | Income | Date |
1 | 900000 | 1-1-2000 |
2 | 180000 | 1-9-2000 |
3 | 300000 | 3-2-2002 |
4 | 100000 | 2-7-2003 |
and my expression is as follows:
dataSource.GroupBy("new (OrDate.Year as Year, OrDate as Month)", "Income").Select("new (Key.Year, Key.Month, Sum(Value) as Income)");
ONLY IF I KNOW EXACTLY WHAT TYPE OF LIST IT IS, DOES THIS WORK; for instance:
. The dataSource type at build time is an issue for me.
. As a result, anytime I add Orders or Products to the list, I receive an exception:
No generic method 'GroupBy' on type 'System.Linq.Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
Can somebody explain how to prevent this while maintaining the source list as a
For group by in LinQ var x = t.GroupBy(gp => gp.Name).OrderBy(group => group.Key).Select(group => Tuple.Create(group.Key, group.Count()));