LINQ Interview Question #117
What is the difference between server-side and client-side evaluation in LINQ?
LINQ Performance, EF Core LINQ, Expressions & Advanced Queries Senior Advanced
Quick Interview Answer
Server-side evaluation means the query provider translates operations so they run at the data source, such as a database. Client-side evaluation means data has reached the application and subsequent operations execute as .NET code.
Detailed Explanation
Server-side evaluation means the query provider translates operations so they run at the data source, such as a database. Client-side evaluation means data has reached the application and subsequent operations execute as .NET code.
Server-side filtering and projection are usually preferred for large database sets because they reduce transferred data. Client-side processing is appropriate when the required logic cannot be translated and the data volume is intentionally bounded.
Code Example
var query = db.Products
.Where(p => p.IsActive) // Server-side
.Select(p => new { p.Id, p.Name });
var result = query
.AsEnumerable()
.Where(x => CustomCheck(x.Name)) // Client-side
.ToList();