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:

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...