Dynamic Linq Select -How to extract the results

dynamic-linq linq

Question

I have a dynamic Linq Select statement of the form

var projection = result.AsQueryable().Select(string.Format("new({0},{1})",
         model.XtabRow, model.XtabColumn));

This works fine and produces an IQueryable of Anonymous types.

However I an unable to convert it into IEnumerable to use linq on it as AsEnumerable method seems to be missing. I had to use reflection to extract field values in the end

There must be a better way - Any help would be great

Thanks

1
0
3/20/2014 2:16:03 PM

Accepted Answer

You can try something like this

var projection = result.AsQueryable().Select(string.Format("new({0},{1})",
     model.XtabRow, model.XtabColumn));

var enumerableProjection = (from dynamic p in projection select p).AsEnumerable();

OR

var projection = result.AsQueryable().Select(string.Format("new({0},{1})",
     model.XtabRow, model.XtabColumn));

var enumerableProjection = projection.Cast<dynamic>().AsEnumerable();
1
3/24/2014 7:03:34 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow