开发者

Convert string to LINQ query

开发者 https://www.devze.com 2023-01-25 05:38 出处:网络
which method or way should be us开发者_开发问答ed to convert a string to a linq query ? Environment: VS 2010/C#I\'m not sure of what you are trying to achieve but if you are referring to creating lin

which method or way should be us开发者_开发问答ed to convert a string to a linq query ?

Environment: VS 2010/C#


I'm not sure of what you are trying to achieve but if you are referring to creating linq queries from strings you could use the dynamic linq library, check it out here http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx


You have to do something like this:

var query =
                db.Customers.Where("Country== @0 and Orders.Count >= @1", "Costa Rica", 10).
                OrderBy("CompanyName").
                Select("New(CompanyName as Name, Phone)");

some parts could be taken from strings, some others (tables) cant


Converting a string to Linq query isn't directly possibly with out some parsing and translation into System.Linq.Expression objects. Neither is trivial.

Check this out for one example.

0

精彩评论

暂无评论...
验证码 换一张
取 消