I m building dynamic lambda expression.I got the following operators working for this code “Contains”,”StartsWith”,”EndsWith”.
Source code
var method = typeof(string).GetMethod(opType.ToString(), new[] { typeof(string) });
var startsWithDishExpr = Expression.Call(argLeft, method, argRight);
But Like operator didnt work.
I tried this code for “Like” Operator
var likeExpression = Expression.Call(
typeof(System.Data.Linq.SqlClient.SqlMethods), "Like", null, argLeft, argRight);
Anyone have answer for this? Please share.
You can’t use
System.Data.Linq.SqlClient.SqlMethods, so you have to create aLikemethod yourself .Example:
Output:
(example implementation from here)
EDIT:
Since you are using Entity Framework, you should use
PatIndexinstead.