I would like to create a IQueryable Where method as shown below:

public static IQueryable Where(this IQueryable source, string predicate, params object[] values)

So instead of Where(u => u.Points >= 20) I could pass a string predicate like Where("Points >= param0", 20)

What would be involved in accomplishing this task?

  • Why do you want to do that? – CodingYoshi Feb 19 '17 at 1:37
  • So a user can input a query or function ((10 * Cos(param0)) + parm1) >= 3, with params (4, 7). I would like a user in a WinForm to enter a predicate with params and this would be executed with a result. – DaveSmith Feb 19 '17 at 1:44
  • See this SO question. – CodingYoshi Feb 19 '17 at 2:02

The code to accomplish what you are asking is large, it is easier to use NuGet package NequeoLinq. Sample code, first add the extension

using Nequeo.Extension;
using Nequeo.Linq.Extension;

On any collection type:

Where("ProOne >= @0 && ProTwo <= @1", 30, 70);

Pass the predicate as a string containing the property names of the collection type and the collection of parameters contained in the predicate (@0, @1 refer to 30 and 70).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.