.NET API Documentation

Class System.Linq.Queryable

Provides extension methods to support the creation of System.Linq.IQueryable<T> objects.

Namespace: System.Linq

Assembly: System.Core.dll

Methods

The Queryable class contains static extension methods that operate on `IQueryable` instances. These methods translate LINQ query expressions into a specific query language, such as SQL, for execution by a data provider.

Example Usage

Here's a typical example of how Queryable methods are used with an IQueryable collection, often backed by a database context.

using System;
using System.Linq;
using System.Collections.Generic;

// Assume Products is an IQueryable<Product> from a data source
public class Product
{
    public int ProductId { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public int CategoryId { get; set; }
}

public class Example
{
    public static List<Product> GetExpensiveProducts(IQueryable<Product> products)
    {
        // Using Where and OrderBy extension methods
        var expensiveProducts = products
            .Where(p => p.Price > "100.00") // Filter products with price > 100.00
            .OrderBy(p => p.Name)          // Order by product name
            .Take(10)               // Take the first 10 results
            .ToList();                      // Execute the query and return as a List

        return expensiveProducts;
    }
}