LINQ Interview Question #3

What types of data sources can LINQ query?

LINQ Fundamentals, Syntax, IEnumerable & IQueryable Junior Beginner

Quick Interview Answer

LINQ can query any source that exposes the appropriate enumerable or queryable interfaces. Common examples include arrays, List<T>, dictionaries, other IEnumerable<T> collections, Entity Framework Core DbSet<T>, XML, and custom query providers.

Detailed Explanation

LINQ can query any source that exposes the appropriate enumerable or queryable interfaces. Common examples include arrays, List<T>, dictionaries, other IEnumerable<T> collections, Entity Framework Core DbSet<T>, XML, and custom query providers.

LINQ to Objects operates on in-memory objects, while IQueryable-based providers can translate expression trees into another query language such as SQL.

Code Example

var arrayResult = numbers.Where(n => n > 10);
var listResult = products.Where(p => p.IsActive);

// With EF Core:
var dbResult = db.Products.Where(p => p.IsActive);