Entity Framework query building methods: why "this" and not lambdas?

I am just starting with EF, and such a query looks like odd:

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

In particular, what sticks out for me is "it.Name". When I was working with LINQ to SQL, almost every filter in the query builder query could be set using lambda, for example, in this case d => d.Name.

I see that there are OrderBy overrides that accept lambdas that return IOrderedQueryable or IOrderedEnumable, but they obviously don't have the Execute method needed to get the ObjectResult, which can then be bound to the database.

It seems strange to me, after all I read about how lambdas make such a sense for these kinds of things and how they are converted to expression trees and then to the target language - why do I need to use it?. ""

+6
c # entity-framework
source share
1 answer

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

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

These are some of the possibilities.

NTN.

+2
source share

All Articles