How does LINQ query execution differ between in-memory collections and databases?
Updated May 16, 2026
Short answer
In-memory LINQ executes delegates directly, while database LINQ translates expressions into SQL via providers like EF Core.
Deep explanation
When working with IEnumerable, LINQ uses compiled delegates that run immediately in CLR memory. In contrast, IQueryable builds expression trees that are parsed by query providers (e.g., Entity Framework Core). These providers translate expressions into SQL or other query languages. This leads to fundamentally different execution models: CPU-bound in-memory iteration vs I/O-bound database execution. The mismatch can cause performance issues if developers unintentionally force client-side evaluation.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro