Поиск  
Always will be ready notify the world about expectations as easy as possible: job change page
May 16, 2022

Best LINQ performance

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

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.

Похожее
Aug 26, 2021
Author: Dumindu De Silva
What is .Net 5 .Net 5 is one of the major and latest releases of Microsoft’s .NET family. It comes with many exciting features compared to the previous released .Net core. The primary goal with the release of .Net 5...
Aug 11, 2021
Author: Mel Grubb
Code Generation Code generation is a great way to apply patterns consistently across a solution or to create multiple similar classes based on some outside input file, or even other classes in the same solution. The tooling has changed over...
Jan 10
Author: MESCIUS inc.
In today’s connected world, data is piling up very fast. We are generating more data than ever in human history, and a lot of this data is getting stored in non-relational formats like JSON documents. JSON has become a ubiquitous...
Feb 2
Author: Jeslur Rahman
If you are embarking on the journey to become a .NET Framework developer in 2024, you’re in for an exciting ride! The .NET ecosystem is vast and constantly evolving. To help you navigate this landscape effectively, we’ve compiled a comprehensive...
Написать сообщение
Тип
Почта
Имя
*Сообщение

RSS
Если вам понравился этот сайт и вы хотите меня поддержать, вы можете
Как мы столкнулись с версионированием и осознали, что вариант «просто проставить цифры» не работает
Три дороги для программиста: эксперт, руководитель, основатель
Soft skills: 18 самых важных навыков, которыми должен владеть каждый работник
PSR Стандарты
Выгорание эволюционирует. Что такое «тихий уход» — новый тренд среди офисных сотрудников
Жесткие факты о софт скилах
«Великое увольнение» продолжается: теперь с работы уходят даже боссы
Универсальный ускоритель инженера: как расти быстрее с помощью проектов
Нагрузочное тестирование: что? где? когда?
Рассуждение на тему, какую базу данных выбирать
LinkedIn: Sergey Drozdov
Boosty
Donate to support the project
GitHub account
GitHub profile