In this article, I will show the most performant way to write queries for a collection of objects in .Net Core. The article discusses the common methods of LINQ and their comparison. After reading this article, you may have to review your project code!
Comparisons were made between query syntax, called LINQ, and method syntax called LAMBDA.
💡 Connect with me on LinkedIn: https://www.linkedin.com/in/hussein-nm/
LINQ_Where (Method name):
Which one do you think is faster?
In this simple performance query, both methods are similar.
Using Any() as the LAMBDA_Any method is faster.
Using First() as the method a LAMBDA call is faster.
Using FirstOrDefault() as the method a LAMBDA call is faster.
Using Last() as the method a LAMBDA call is faster.
Using LastOrDefault() as the method a LAMBDA call is faster.
As shown in this article, you should always use Any(), First(), FirstOrDefault(), Last(), LastOrDefault, or Where() at the beginning of a LAMBDA statement.