using System.Collections.Generic;
using System.Linq.Expressions;
public string FirstName {get;set;}
public static void Main()
var _people = new List<Person>();
_people.Add(new Person() {FirstName = null});
_people.Add(new Person() {FirstName = "Robert"});
_people.Add(new Person() {FirstName = "Bobert"});
_people.Add(new Person() {FirstName = "Norbert"});
_people.Add(new Person() {FirstName = "John"});
_people.Add(new Person() {FirstName = "John"});
Console.Write("LAMBDA TREE...");
Console.WriteLine("person => Concat(person.FirstName, '').ToLower().Contains([SEARCH_TERM])");
Expression searchTerm = Expression.Constant("bert");
ParameterExpression pe = Expression.Parameter(typeof(Person), "person");
Expression lt = Expression.Property(pe, typeof(Person).GetProperty("FirstName"));
var strC = Expression.Constant("");
var methodInfo = typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) });
var concat = Expression.Call(methodInfo, lt, strC);
Expression left = Expression.Call(concat, typeof(string).GetMethod("ToLower", System.Type.EmptyTypes));
var containsExpression = Expression.Call(left, "contains", null, searchTerm);
Console.WriteLine(containsExpression.ToString());
var lambda = Expression.Lambda<Func<Person,bool>>(containsExpression, pe);
var compiledLambda = lambda.Compile();
var result = _people.Where(compiledLambda).ToList();
foreach (Person p in result) {
Console.WriteLine("DONE");