Reputation: 21
which method or way should be used to convert a string to a linq query ?
Environment: VS 2010/C#
Upvotes: 2
Views: 11662
Reputation: 1005
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
Upvotes: 1
Reputation: 15559
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.
Upvotes: 0
Reputation: 37366
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
Upvotes: 1