Junior — Middle
What methods make up the IQueryable interface in .NET?
sobes.tech AI
Answer from AI
The IQueryable<T> interface in .NET extends IEnumerable<T> and is designed for building data source queries with deferred execution and translation into various formats (e.g., SQL).
Main methods and properties of IQueryable<T>:
- Expression Expression { get; } — returns the LINQ expression describing the query.
- Type ElementType { get; } — the type of elements returned by the query.
- IQueryProvider Provider { get; } — the provider that executes the query.
Additionally, IQueryable<T> inherits methods from IEnumerable<T>, such as GetEnumerator().
Example usage:
IQueryable<Customer> query = dbContext.Customers.Where(c => c.Age > 18);
// The query is not executed immediately but only when iterated over or when calling ToList()
var adults = query.ToList();
Thus, IQueryable provides an interface for building and executing queries with optimization and translation capabilities.