Linq : "New " keyword not working for multi fields selection (Dynamic Library)
I updated the DynamicLibrary code to be able to launch a query such as :
objects.Where(obj => obj.color == "blue").Select(obj => obj.name);
It's working fine. Now I'm trying to get this one working :
objects.Where(obj => obj.color == "blue").Select(new {obj.name, obj.type});
Not working... Then, I looked at 开发者_如何学Gothe "New" keyword parser in DynamicLibrary.cs. So I tried :
objects.Where(obj => obj.color == "blue").Select("new(obj.name, obj.type)");
And now I'm getting something like : "')' is missing"..
(I'm still a beginner with Linq)
Thanks for your help.
Seems like your
objects.Where(obj => obj.color == "blue").Select(new {obj.name, obj.type});
should be actually
objects.Where(obj => obj.color == "blue").Select(obj => new {obj.name, obj.type});
Let me know if that helps.
There is an evolution of the Dynamic Linq library that uses the c# dynamic keyword so you don't have strings available in nuget, and while it's not complete the original dynamic linq sample code library wasn't quite complete either, my be worth checking out. Here is a blog post about it.
精彩评论