Tolitech.Queryable.Extensions 1.0.0-preview.3

This is a prerelease version of Tolitech.Queryable.Extensions.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Tolitech.Queryable.Extensions --version 1.0.0-preview.3
                    
NuGet\Install-Package Tolitech.Queryable.Extensions -Version 1.0.0-preview.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tolitech.Queryable.Extensions" Version="1.0.0-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tolitech.Queryable.Extensions" Version="1.0.0-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="Tolitech.Queryable.Extensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tolitech.Queryable.Extensions --version 1.0.0-preview.3
                    
#r "nuget: Tolitech.Queryable.Extensions, 1.0.0-preview.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tolitech.Queryable.Extensions@1.0.0-preview.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tolitech.Queryable.Extensions&version=1.0.0-preview.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Tolitech.Queryable.Extensions&version=1.0.0-preview.3&prerelease
                    
Install as a Cake Tool

Tolitech.Queryable.Extensions

The Tolitech.Queryable.Extensions library provides utility methods to simplify querying operations on IQueryable data sources. It includes features for dynamic ordering and pagination, enabling efficient data retrieval and manipulation in LINQ queries.


Features

1. Dynamic Ordering

  • Allows sorting IQueryable collections dynamically based on property names specified in a string.
  • Supports multi-level sorting with multiple fields and ascending/descending order.

2. Pagination

  • Provides an easy way to implement paging logic with parameters for page number and page size.

Usage

1. Dynamic Ordering with OrderByExpression

Use the OrderByExpression method to dynamically sort an IQueryable collection based on a string that specifies the property and order.

Syntax
public static IQueryable<T> OrderByExpression<T>(
    this IQueryable<T> query, 
    string orderByString
)
  • query: The data source to sort.
  • orderByString: A comma-separated string specifying the sorting criteria. Use : to indicate sorting order (asc or desc). Default is asc.
Example
using Tolitech.Queryable.Extensions;

// Sample data
var products = new List<Product>
{
    new Product { Id = 1, Name = "Apple", Price = 10 },
    new Product { Id = 2, Name = "Orange", Price = 8 },
    new Product { Id = 3, Name = "Banana", Price = 5 }
}.AsQueryable();

// Order by Name (ascending) and then Price (descending)
string orderByString = "Name,Price:desc";

var sortedProducts = products.OrderByExpression(orderByString);

foreach (var product in sortedProducts)
{
    Console.WriteLine($"{product.Name} - {product.Price}");
}
Output
Apple - 10
Banana - 5
Orange - 8

2. Pagination with Paginate

Use the Paginate method to retrieve a specific page of items from an IQueryable collection.

Syntax
public static IQueryable<T> Paginate<T>(
    this IQueryable<T> source, 
    int pageNumber, 
    int pageSize
)
  • source: The data source to paginate.
  • pageNumber: The page number to retrieve (starting at 1).
  • pageSize: The number of items per page.
Example
using Tolitech.Queryable.Extensions;

// Sample data
var products = new List<Product>
{
    new Product { Id = 1, Name = "Apple", Price = 10 },
    new Product { Id = 2, Name = "Orange", Price = 8 },
    new Product { Id = 3, Name = "Banana", Price = 5 },
    new Product { Id = 4, Name = "Grapes", Price = 15 },
    new Product { Id = 5, Name = "Pineapple", Price = 20 }
}.AsQueryable();

// Paginate data: Page 2, 2 items per page
int pageNumber = 2;
int pageSize = 2;

var paginatedProducts = products.Paginate(pageNumber, pageSize);

foreach (var product in paginatedProducts)
{
    Console.WriteLine($"{product.Name} - {product.Price}");
}
Output
Banana - 5
Grapes - 15

API Reference

1. OrderByExpression

  • Dynamically sorts the IQueryable based on the specified string.
  • Supports multi-level sorting using a comma-separated list.
  • Default sorting order is ascending (asc).

Example Input Strings:

  • "Name": Sorts by Name ascending.
  • "Price:desc": Sorts by Price descending.
  • "Category,Price:desc": Sorts by Category ascending, then by Price descending.

2. Paginate

  • Implements paging logic for IQueryable data sources.
  • Skips records based on pageNumber and retrieves pageSize number of items.

Example Parameters:

  • pageNumber = 1, pageSize = 5: Returns the first 5 items.
  • pageNumber = 2, pageSize = 3: Skips the first 3 items and returns the next 3 items.
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview.4 119 7/17/2025
1.0.0-preview.3 119 7/14/2025
1.0.0-preview.2 124 7/1/2025
1.0.0-preview.1 113 12/6/2024