Josh Kodroff
Josh Kodroff

Reputation: 28131

Is there any performance cost in breaking up a single Where() with && into 2 Where() calls (in EF)?

In Entity Framework, is there any performance cost of doing this...

var businesses = dbContext.Businesses.Where(x => x.Name.ToLower().StartsWith(name) && businessTypes.Contains(x.Type));

... versus this?

var businesses = dbContext.Businesses.Where(x => x.Name.ToLower().StartsWith(name)).Where(x => businessTypes.Contains(x.Type));

I prefer to do the latter since it's easier to read, but not if there's a serious performance hit on the generated SQL.

Upvotes: 0

Views: 46

Answers (1)

BrokenGlass
BrokenGlass

Reputation: 160922

No there is no performance cost - the EF Linq provider maps both to the same SQL query. I personally find the first version much more readable though.

Upvotes: 3

Related Questions