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

Était-ce utile?

La solution

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();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top