tags:

views:

334

answers:

2

Does it matter if you are using 'And' or 'AndAlso' in linq queries in vb.net? I know in normal operations 'AndAlso' is short circuit and so will often be faster, but I don't know if that carries over into linq queries. Does it matter if the linq query is against a database or against an in memory collection?

+8  A: 

For LINQ to object queries, it would definitely matter. For other LINQ providers, it depends on the provider itself. At the expression tree level, they are different but the provider might choose to translate/run it the same way. For instance, there's no equivalent notion in SQL so LINQ to SQL translates them to identical SQL.

Mehrdad Afshari
+1  A: 

Whether or not to use And vs. AndAlso is very dependent on the context of the usage. However it's almost always preferable to use AndAlso over And.

The short circuit quality of AndAlso will carry over to LINQ queries

JaredPar