Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does 'And' vs 'AndAlso' matter with linq in vb.net?

Tags:

vb.net

linq

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?

like image 944
thefroatgt Avatar asked Jun 28 '09 21:06

thefroatgt


2 Answers

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.

like image 188
mmx Avatar answered Sep 24 '22 21:09

mmx


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

like image 44
JaredPar Avatar answered Sep 25 '22 21:09

JaredPar