seniorLINQ

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 pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More LINQ interview questions

View all →