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}Important notes
Section titled “Important notes”- Only a subset of C# methods can be translated to SQL
- Use
AsEnumerable()orToList()to switch to client evaluation - Deferred execution works with
IQueryable<T>
Real-world usage example
Section titled “Real-world usage example”Database paging and filtering: EF Core translates Skip and Take to OFFSET and FETCH in SQL.
Example: EF Core querying documentation explains translation rules.