Skip to content

EF Core SQL translation

Context: LINQ to Entities (Entity Framework Core) translates LINQ queries to SQL, executing them on the database server.

using (var context = new AppDbContext())
{
var activeCustomers = context.Customers
.Where(c => c.IsActive && c.Orders.Any())
.OrderBy(c => c.Name)
.Take(10)
.ToList(); // SQL generated and executed
}
  • Only a subset of C# methods can be translated to SQL
  • Use AsEnumerable() or ToList() to switch to client evaluation
  • Deferred execution works with IQueryable<T>

Database paging and filtering: EF Core translates Skip and Take to OFFSET and FETCH in SQL.

Example: EF Core querying documentation explains translation rules.