问题
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:
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();
来源:https://stackoverflow.com/questions/22534191/dynamic-linq-select-how-to-extract-the-results