I am attempting to generate an Expression tree that ultimately calls a series of GroupBy methods on the Enumerable type.
In simplified form I am attempting something like this:
IEnumerable<Data> list = new List<Data>{new Data{Name = "A", Age=10},
new Data{Name = "A", Age=12},
new Data{Name = "B", Age=20},
new Data{Name="C", Age=15}};
Expression data = Expression.Parameter(typeof(IEnumerable<Data>), "data");
Expression arg = Expression.Parameter(typeof(Data), "arg");
Expression nameProperty = Expression.PropertyOrField(arg, "Name");
Expression group = Expression.Call(typeof(Enumerable), "GroupBy", new Type[] { typeof(Data), typeof(string) }, data, nameProperty);
The call to Expression.Call at the end throws "No method 'GroupBy' on type 'System.Linq.Enumerable' is compatible with the supplied arguments."
I am doing a similar thing, in a similar fashion with Enumerable.OrderBy
successfully and am stumped.
Any help is appreciated.