开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜