LightQuery.Shared 1.1.0

.NET Standard 1.6 .NET Framework 4.6.1
There is a newer version of this package available.
See the version list below for details.
dotnet add package LightQuery.Shared --version 1.1.0
NuGet\Install-Package LightQuery.Shared -Version 1.1.0
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="LightQuery.Shared" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LightQuery.Shared --version 1.1.0
#r "nuget: LightQuery.Shared, 1.1.0"
#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.
// Install LightQuery.Shared as a Cake Addin
#addin nuget:?package=LightQuery.Shared&version=1.1.0

// Install LightQuery.Shared as a Cake Tool
#tool nuget:?package=LightQuery.Shared&version=1.1.0


Build Status

Online Documentation

This project aims to provide a lightweight ActionFilterAttribute that takes care of sorting and paginating Asp.Net Core API results.

This project is for you if you're still waiting for OData support in Asp.Net Core, even though you only need the most basic of operations. It's also for everyone tired of writing like the 17th string sort = "Username" parameter and lines over lines of switch statements in their controller actions.

It supports EntityFrameworkCores async query materialization with the optional LightQuery.EntityFrameworkCore package.


In addition to the C# client, there's also a client for Angular 5+ on npm: ng-lightquery


NuGet MyGet

The package is available on nuget. Daily builds are on myget.

MyGet feed:

PM> Install-Package LightQuery

Includes the core functionality to sort and paginate Asp.Net Core controller results

PM> Install-Package LightQuery.EntityFrameworkCore

Includes support for EntityFramework.Core async query materialization

PM> Install-Package LightQuery.Client

Includes LightQuery models and the QueryBuilder utility

Both NETStandard 1.6 and .Net 4.6.1 are supported.

Documentation - Server

See below how to apply sorting & filtering to your API controllers. At a glance:

  • Return an ObjectResult from your controller with an IQueryable value
  • Use sort to sort, page & pageSize for pagination in your requests

You can find a demo in the integration test projects for an example of using this in an Asp.Net Core MVC application for sorting and filtering.


using LightQuery;

public class ApiController : Controller
    [ProducesResponseType(typeof(IEnumerable<User>), 200)]
    public IActionResult GetValues()
        var values = _repository.GetAllValuesAsQueryable();
        return Ok(values);  

Annotate your controller actions with the LightQueryAttribute and it takes care of applying url queries to the result. All ObjectResults (docs) that have an IQueryable value will be transformed. You're free to return any other results, too, from the annotated action and it will simply be ignored.

Example: desc

This will sort the result by its Email property (it is title-cased if no email property is found) in descending order.

Pagination & Sorting

Paging is active when the request includes pagination query parameters or via explicitly setting the forcePagination parameter to true in the attributes' constructor. Sorting works in combination with paging.

using LightQuery;

public class ApiController : Controller
    [LightQuery(forcePagination: true, defaultPageSize: 3)]
    [ProducesResponseType(typeof(PaginationResult<User>), 200)]
    public IActionResult GetValues()
        var values = _repository.GetAllValuesAsQueryable();
        return Ok(values);  



    "page": 2,
    "pageSize": 3,
    "totalCount": 20,
    "data": [
        { "userName": "Dave", "email": "" },
        { "userName": "Emilia", "email": "" },
        { "userName": "Fred", "email": "" }

Async Materialization

The LightQuery.EntityFrameworkCore package provides an AsyncLightQueryAttribute. This can be used for data sources that support async materialization of queries, e.g. var result = await context.Users.ToListAsync().

Documentation - C# Client

The LightQuery.Client package contains the PaginationResult<T> base class as well as a QueryBuilder utlity class to construct queries.


using LightQuery.Client;

var url = QueryBuilder.Build(page: 3, pageSize: 25, sortParam: "email");
var response = await _client.GetAsync(url);
var responseContent = await response.Content.ReadAsStringAsync();
var deserializedResponse = JsonConvert.DeserializeObject<PaginationResult<User>>(responseContent);


The LightQuery.Client package contains an abstract class PaginationBaseService<T> that can be used in reactive clients. It is similar in functionality to the TypeScript client.

Documentation - TypeScript & Angular

There is an Angular example that can be used standalone or in combination with a @angular/material2 DataTable and its pagination and sort functionality.

Example with Material 2 DataTable

<md-table [dataSource]="dataSource"
          [mdSortDirection]="usersService.sort?.isDescending ? 'desc' : 'asc'"
    <ng-container cdkColumnDef="email">
        <md-header-cell md-sort-header *cdkHeaderCellDef> Email </md-header-cell>
        <md-cell *cdkCellDef="let row">
    <md-header-row *cdkHeaderRowDef="['email']"></md-header-row>
    <md-row *cdkRowDef="let row; columns: ['email'];"></md-row>
<md-paginator [length]="usersPaginated.totalCount"
              [pageIndex]=" - 1"
export class UsersComponent implements OnInit, OnDestroy {

    constructor(public userService: UserService) { }

    private usersPaginatedSubscription: Subscription;
    usersPaginated: PaginationResult<User>;
    dataSource: DataSource<User>;

    onPage(pageEvent: PageEvent) { = pageEvent.pageIndex + 1;
        this.userService.pageSize = pageEvent.pageSize;

    onSort(event: { active: string, direction: string }) {
        if (!event.direction) {
            this.userService.sort = null;
        } else {
            this.userService.sort = { propertyName:, isDescending: event.direction === 'desc' };

    ngOnInit() {
        this.dataSource = this.userService;
        this.usersPaginatedSubscription = this.userService.paginationResult.subscribe(r => this.usersPaginated = r);

    ngOnDestroy() {

MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.6 is compatible.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on LightQuery.Shared:

Package Downloads

ASP.NET Core ActionFilter for sorting and pagination


ASP.NET Core ActionFilter for sorting and pagination with support for EntityFrameworks async materialization

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.0 3,761 11/25/2022
2.2.2 2,346 8/22/2022
2.2.1 1,709 8/3/2022
2.2.0 1,852 7/1/2022
2.1.0 17,952 8/25/2021
2.0.0 2,937 7/15/2021
1.9.1 24,640 7/16/2020
1.9.0 3,289 6/1/2020
1.8.1 1,550 5/14/2020
1.8.0 1,825 1/6/2020
1.7.2 3,179 10/16/2019
1.7.1 1,229 10/16/2019
1.7.0 1,334 10/14/2019
1.6.2 1,288 9/29/2019
1.6.1 3,480 8/9/2019
1.6.0 1,385 8/6/2019
1.5.2 9,219 1/31/2019
1.5.1 1,498 1/31/2019
1.5.0 1,654 11/29/2018
1.4.0 1,634 11/27/2018
1.3.0 3,321 9/15/2018
1.1.0 7,574 11/16/2017
1.0.2 1,653 8/9/2017

1.1.0: Client now contains a PaginationBaseService
     1.0.2: Initial Release. Version number is aligned with LightQuery package