Entity Framework Core Interview Question #22

What is LINQ in EF Core?

EF Core Fundamentals & DbContext Junior Beginner

Quick Interview Answer

LINQ allows developers to express database queries using strongly typed C# expressions. EF Core examines the expression tree and translates supported parts into SQL for the configured relational provider.

Detailed Explanation

LINQ allows developers to express database queries using strongly typed C# expressions. EF Core examines the expression tree and translates supported parts into SQL for the configured relational provider.

Methods such as Where, Select, OrderBy, Join, Any, Count, FirstOrDefault, and GroupBy can participate in query translation.

Developers should inspect generated SQL and performance for important queries because concise LINQ can still translate into expensive database operations.

Code Example

var products = await db.Products
    .Where(p => p.Price >= 100)
    .OrderByDescending(p => p.Price)
    .Select(p => new
    {
        p.Id,
        p.Name,
        p.Price
    })
    .ToListAsync();