How do I build Linq Expressions for aggregate classes? Let me explain with an example of what I am trying to do. Say, I want to find all employees with pay not equal to 50000 and here's the class structure.
Employee e1 = new Employee { Name = "Jane", PDetail = new PayDetail { Salary = 100000 } };
Employee e2 = new Employee { Name = "Joe", PDetail = new PayDetail { Salary = 50000 } };
emps.Add(e1);
emps.Add(e2);
//I started doing it this way and this code DOES NOT compile
var parameter = Expression.Parameter(typeof(PayDetail));
var where = Expression.NotEqual(Expression.Property(parameter, "Salary"), Expression.Constant(50000));
var pred = Expression.Lambda(where, parameter);
var query = Enumerable.Where(emps, (Func<PayDetail, Boolean>)pred.Compile());
EDIT: Any help with the null issue (as noted in the comments)? Thanks