Thursday, November 26, 2015

C# Expression in Dynamic Linq Queries

Currently dynamic linq operators created using System.Linq.Expressions.Expression object do not support sql "IN" operator, there is a way to implement it however, just add a simple expression building tree like in the example here:

pe = Expression.Parameter(typeof(myClient), "clt"); PropertyInfo propertyInfo = typeof(myClient).GetProperty("PropertyFieldName"); MemberExpression m = Expression.MakeMemberAccess(pe, propertyInfo); ConstantExpression c = Expression.Constant("SearchFrase", typeof(string)); MethodInfo mi = typeof(string).GetMethod("Contains", new Type[] { typeof(string) }); e1 = exp.Expression.Call(m, mi, c);


Reference: 

http://stackoverflow.com/questions/6907103/how-to-create-a-dynamic-contains-or-like-expression-to-be-used-with-linq-again



No comments:

SSL Error - The connection for this site is not secure

 After cloning a git repo of dot net framework website and trying to run it all I could see was this error Turns out the fix was to simply e...