6 question(s)
What is LINQ and what is deferred execution?
Beginner
LINQ queries collections and data sources uniformly. Most operators are lazy: the query executes when enumerated (foreach/ToList), so it reflects the latest data.
var q = nums.Where(n => n > 2); // not run yet
nums.Add(5);
foreach (var n in q) {} // runs now, sees 5
Real-world example
Building a filter then materialising it only after paging parameters are known.
What is the difference between IEnumerable and IQueryable in LINQ?
Intermediate
IEnumerable executes in memory (LINQ-to-Objects); IQueryable builds an expression tree a provider (EF Core) translates to SQL, so filtering happens in the database.
IQueryable<User> q = db.Users.Where(u => u.Active); // -> SQL WHERE
IEnumerable<User> m = list.Where(u => u.Active); // in memory
Real-world example
Calling Where before ToList on a DbSet pushes the filter to the database instead of loading every row.
What is the difference between First, FirstOrDefault and Single?
Intermediate
First returns the first match or throws if none; FirstOrDefault returns default if none; Single expects exactly one and throws otherwise.
var a = xs.First(x => x.Id==1);
var b = xs.FirstOrDefault(x => x.Id==1);
var c = xs.Single(x => x.Id==1);
Real-world example
Use Single for a unique-key lookup where duplicates would indicate a data bug.
What is the difference between Select and SelectMany?
Intermediate
Select projects one-to-one (giving a sequence of sequences if the selector returns a collection); SelectMany flattens those into one sequence.
var tags = posts.Select(p => p.Tags); // IEnumerable<List<string>>
var flat = posts.SelectMany(p => p.Tags); // IEnumerable<string>
Real-world example
Getting one flat list of all line items across all orders.
How does GroupBy translate and what performance pitfalls exist?
Advanced
GroupBy partitions by a key into IGrouping<TKey,T>. In LINQ-to-Objects it buffers; in EF Core only certain shapes translate to SQL GROUP BY, otherwise it fails or evaluates client-side.
var byCat = products.GroupBy(p => p.Category)
.Select(g => new { g.Key, Total = g.Sum(p => p.Price) });
Real-world example
Summing sales per region for a dashboard — ensure it translates to SQL for large tables.
Why can LINQ cause the N+1 query problem and how do you fix it?
Advanced
Accessing a navigation property inside a loop triggers a query per item. Fix it by eager-loading with Include or projecting the needed data in one query.
// N+1: foreach (var o in orders) use(o.Customer.Name);
var data = db.Orders.Include(o => o.Customer).ToList();
Real-world example
A report that reads each order's customer separately hammers the DB; Include batches it.