How to create LINQ Expression Tree to select an anonymous type

前端 未结 9 730
夕颜
夕颜 2020-11-22 12:12

I would like to generate the following select statement dynamically using expression trees:

var v = from c in Countries
        where c.City == \"London\"
           


        
9条回答
  •  余生分开走
    2020-11-22 12:46

    You could use the Dynamic Expression API which allows you to dynamically build your select statement like this:

     Select("new(,,...)");
    

    You need the Dynamics.cs file from the LINQ and language samples for Visual Studio for this to work, both are linked at the bottom of this page. You can also see a working example showing this in action on at the same URL.

提交回复
热议问题