optimizing Where clause in linq
What's better?
1) several Where clauses with one filter per clause
2) 1 Where clause with lots of && betwe开发者_运维百科en filters
I'm using linq-to-sql
Thanks.
In linq-to-objects multiple &&
is most likely faster since it incurs the delegate invocation overhead only once.
For most IQueryable based linq implementations it's probably almost the same for both of them, since they most likely will be optimized to the same internal query. The amount of work done by the optimizer might differ slightly.
For linq-to-sql it doesn't matter because the query is evaluated once and executed when you need it.
However, you still need to worry about the performance of the query itself. You can get into trouble by not having the correct indexes in place.
精彩评论