LINQ vs IQueryable?
LINQ vs IQueryable
What interviewers test
- Deferred execution
- DB performance
LINQ (IEnumerable)
var data = users.Where(x => x.Age > 30).ToList();
- Executes in memory
IQueryable
var data = db.Users.Where(x => x.Age > 30);
- Translates to SQL
- Executes in DB
Interview line
“IQueryable builds expressions; IEnumerable executes them.”
🔟 Write clean, production-ready C# code
What interviewers test
- Professional maturity
Principles
- Small methods
- Clear naming
- No magic values
- Proper exceptions
public class OrderService
{
public void PlaceOrder(Order order)
{
if (order == null)
throw new ArgumentNullException(nameof(order));
Validate(order);
Save(order);
}
private void Validate(Order order)
{
if (order.Total <= 0)
throw new InvalidOperationException("Invalid total");
}
private void Save(Order order)
{
// persistence logic
}
}