score:0

I'm not sure why you need the Expression - just use the Func. This should work:

Func<Employee, Employee, Dto> selector = (boss, grunt) => new Dto 
{ 
Id = boss.EmployeeID, Name = grunt.FirstName 
}; 

using (var db = new NorthwindDataContext()) 
{ 
var q = from boss in db.Employees 
        from grunt in db.Employees.Where(p => p.ReportsTo == boss.EmployeeID).DefaultIfEmpty() 
        select selector(boss, grunt)
} 

score:0

You cannot use query syntax always, there are cases where you can express computations only with method chains. In this specific case the query syntax would introduce a lambda behind the scenes if the predicate was inline, but you are putting it into a variable so you have no way to specify how that variable should be used, as you would with a lambda, supported by query syntax.


Related Articles