I am using Dyanmic LINQ from the VS2010 sample code as I am trying to create a groupby LINQ expression. I want to allow the user the ability to select at runtime the properties for grouping by / by, as well as the grouping period (year, quarter, month). Because of this, I decided to go for Dynamic LINQ.
Here is an example of my data:
ID | Income | OrDate |
1 | 900,000 | 1-1-2000 |
2 | 180000 | 1-9-2000 |
3 | 300,000 | 3-2-2002 |
4 | 100,000 | 2-7-2003 |
and the expression I'm building looks like this:
dataSource.GroupBy("new (OrDate.Year as Year, OrDate as Month)", "Income").Select("new (Key.Year, Key.Month, Sum(Value) as Income)");
This works well ONLY I know the exact type of list; for example: List<Product>or List<Order>. My problem is that the dataSource type is at compile time List<object>. Because of this, when I fill out the list using Orders or Products, I get 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 someone tell me how to avoid this and keep the original list as List<object>?
source
share