Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework query builder methods: why "it" and not lambdas?

I'm just getting started with EF and a query like the following strikes me as odd:

var departmentQuery =
                schoolContext.Departments.Include("Courses").
                OrderBy("it.Name");

Specifically, what sticks out to me is "it.Name." When I was tooling around with LINQ to SQL, pretty much every filter in a query-builder query could be specified with a lambda, like, in this case, d => d.Name.

I see that there are overrides of OrderBy that take lambdas that return an IOrderedQueryable or an IOrderedEnumable, but those obviously don't have the Execute method needed to get the ObjectResult that can then be databound.

It seems strange to me after all I've read about how lambdas make so much sense for this kind of stuff, and how they are translated into expression trees and then to a target language - why do I need to use "it.Name"?

like image 488
nlawalker Avatar asked Jun 15 '10 21:06

nlawalker


1 Answers

I get lamdba expressions with mine; I can do Where (it.SomeProperty == 1)... do you have System.Linq as a namespace? You can try restructuring as:

var departmentQuery = from d in schoolContext.Departments.Include("Courses") orderby d.Name select d;

Those are some possibilities.

HTH.

like image 60
Brian Mains Avatar answered Oct 27 '22 15:10

Brian Mains