开发者

Entity Framework Linq query: .Where chain vs &&

开发者 https://www.devze.com 2023-02-10 21:02 出处:网络
This question pertains to query optimization using Linq with the Entity Framework. Is there any difference between chaining .Where clauses and using && in a single .Where clause of a linq que

This question pertains to query optimization using Linq with the Entity Framework.

Is there any difference between chaining .Where clauses and using && in a single .Where clause of a linq query with the entity framwork?

E.g.: suppose I have the following code:

var result = context.SomeEntity.Where(exp1).Where(exp2);

or

开发者_如何学Pythonvar result = context.SomeEntity.Where(exp1 && exp2);

When evaluating these statements, which yield the same result, does the linq and the entity framework evaluate them in the same way? i.e., will both have the same execution plan, and therefore be equally efficient?


Yes both will have the same execution plan. I have added a sql trace and both create the same SQL statements


I always go with the && because it makes the code easier to read. By using multiple Where this will create a lot of extra noise and take focus off of the logic.

0

精彩评论

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

关注公众号