Client evaluation versus server evaluation
In this section, we will discuss the difference between client evaluation and server evaluation. In the old versions of EF Core (earlier than EF Core 3.0), the wrong usage of LINQ queries that have client evaluation can cause significant performance issues. Let's see what client evaluation and server evaluation are.
When we use EF Core to query data from the database, we can just write LINQ queries, and EF Core will translate the LINQ queries into SQL queries and execute them against the database. However, sometimes, the LINQ operation must be executed on the client side. Check the following code in the SearchInvoices
action method in the InvoicesController
class:
var list = await context.Invoices .Where(x => x.ContactName.Contains(search) || x.InvoiceNumber.Contains(search)) .ToListAsync();
When we use the Contains()
method, EF Core can translate the LINQ query into the following...