I have an expression tree project which works well apart from when I use the GroupBy statement. For statements such as “Where” and “OrderBy” the following line returns a “System.Linq.OrderedEnumerable”
var result = theQueryableSource.Provider.Execute(newExp);
The following line then works correctly as expected.
var test = ((IEnumerable<T>) result).GetEnumerator();
If I use the “GroupBy” statement, the first line of code returns a “System.Linq.GroupedEnumerable”. When the second line runs I get an exception:
Unable to cast object of type 'System.Linq.GroupedEnumerable3 [EntityItemInterfaceClassLib. ReaderEntityItem,System.Nullable
1[System.Int32], EntityItemInterfaceClassLib. ReaderEntityItem]' to type 'System.Collections.Generic.IEnumerable`1[EntityItemInterfaceClassLib. ReaderEntityItem]'.
Can anyone advise on how I can cast the GroupedEnumerable to IEnumerable, or explain what is going wrong?