RU EN
May 16, 2022

Best LINQ performance

Best LINQ performance
Автор:
Hussein NM
Источник:
Просмотров:
4683
Best LINQ performance favorites 0

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/

✨ Where()

LINQ_Where (Method name):

LAMBDA_Where:

🚀 Performance

Which one do you think is faster?

In this simple performance query, both methods are similar.

✨ Any()

LINQ_Any:

LAMBDA_Where_Any:

LAMBDA_Any:

🚀 Performance

Using Any() as the LAMBDA_Any method is faster.

✨ First()

LINQ_First:

LAMBDA_Where_First:

LAMBDA_First:

🚀 Performance

Using First() as the method a LAMBDA call is faster.

✨ FirstOrDefault()

LINQ_FirstOrDefault:

LAMBDA_Where_FirstOrDefault:

LAMBDA_FirstOrDefault:

🚀 Performance

Using FirstOrDefault() as the method a LAMBDA call is faster.

✨ Last()

LINQ_Last:

LAMBDA_Where_Last:

LAMBDA_Last:

🚀 Performance

Using Last() as the method a LAMBDA call is faster.

✨ LastOrDefault()

LINQ_LastOrDefault:

LAMBDA_Where_LastOrDefault:

LAMBDA_LastOrDefault:

🚀 Performance

Using LastOrDefault() as the method a LAMBDA call is faster.

Conclusion

As shown in this article, you should always use Any(), First(), FirstOrDefault(), Last(), LastOrDefault, or Where() at the beginning of a LAMBDA statement.

Похожее
May 12, 2023
Author: Alex Maher
Language Integrated Query (LINQ) is a powerful feature in C# .NET that allows developers to query various data sources using a consistent syntax. In this article, we’ll explore some advanced LINQ techniques to help you level up your skills and...
Nov 19, 2020
We will demonstrate how to setup Elasticsearch and learn how to write basics statements. You will learn about the structure, commands, tools in Elasticsearch API and get it up and running using standard settings. Introduction We will be talking about...
Jul 11, 2021
Author: Sasha Mathews
In C#, reference types can be assigned null values. This is something that developers will have to live with until they use classes to create software. Unfortunately, the folks at Microsoft cannot simply disallow null assignment to reference variables at...
May 16, 2024
Author: Paul Balan
Pagination is in front of us everyday yet we take it for granted kind of like we do with most things. It’s what chunks huge lists of data (blog posts, articles, products) into pages so we can navigate through data....
Написать сообщение
Тип
Почта
Имя
*Сообщение
RSS
Если вам понравился этот сайт и вы хотите меня поддержать, вы можете
9 главных трендов в разработке фронтенда в 2024 году
Как мы столкнулись с версионированием и осознали, что вариант «просто проставить цифры» не работает
Переход от монолита к микросервисам: история и практика
14 вопросов об индексах в SQL Server, которые вы стеснялись задать
Performance review, ачивки и погоня за повышением грейда — что может причинить боль сотруднику IT-компании?
Тестирование PRTG Network Monitor и сравнение с Zabbix
Путеводитель по репликации баз данных
Soft skills: 18 самых важных навыков, которыми должен владеть каждый работник
Система визуализации и мониторинга. Grafana + Prometheus
Погружение в 0.0.0.0 Day: как «нулевой» IP-адрес позволяет взломать локальную сеть
Boosty
Donate to support the project
GitHub account
GitHub profile