LINQ to Entities - Dynamic select for specify columns
I can create a select query that retrieves only the specific columns (static in code) for LINQ to entities
开发者_开发技巧from Example in new Enities.Table
select new { Example.Column1. Example.Column2, ... }
But I can´t figure out how to select Column1, Column2 dynamic (e.g. from string[]). Thanks
Standard LINQ doesn't support that - you must download library called Dynamic LINQ or build expression tree manually. Dynamic LINQ will allow you to call queries like:
var query = Entities.Table.Select("new(Column1,Column2)");
But by using dynamic approach you will lose the main reason for using LINQ - compile time checking. You can in the same way use Entity SQL instead of LINQ and build your queries from strings.
精彩评论