LINQ Interview Question #105
How does Entity Framework Core translate LINQ to SQL?
LINQ Performance, EF Core LINQ, Expressions & Advanced Queries Senior Advanced
Quick Interview Answer
EF Core builds an IQueryable expression tree as LINQ operators are composed. When the query executes, EF Core analyzes supported expressions, translates them into a database command, sends that command to the database, and materializes the returned data.
Detailed Explanation
EF Core builds an IQueryable expression tree as LINQ operators are composed. When the query executes, EF Core analyzes supported expressions, translates them into a database command, sends that command to the database, and materializes the returned data.
Not every .NET method can be translated. Provider support and the shape of the expression determine whether an operation can execute on the database server.
Code Example
var result = await db.Products
.Where(p => p.Price > 100)
.OrderBy(p => p.Name)
.Select(p => new { p.Id, p.Name })
.ToListAsync();