开发者

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.I开发者_StackOverflownclude("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"?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜