KendoNET.DynamicLinq
Description
KendoNET.DynamicLinq implements server paging, filtering, sorting, grouping, and aggregating to Kendo UI via Dynamic Linq for .NET 10.
Prerequisites
- .NET 10. Consumers on .NET Standard, .NET Framework, .NET Core 1.x ~ 3.x, or .NET 5 ~ 9 should use the 3.x releases instead.
- You must add custom
ObjectToInferredTypesConverter to your JsonSerializerOptions since System.Text.Json doesn't deserialize inferred types to object properties, see
the sample code
and reference.
Usage
- Add the KendoNET.DynamicLinq NuGet package to your project.
- Configure your Kendo DataSource to send its options as JSON.
parameterMap: function(options, type) {
return kendo.stringify(options);
}
- Configure the
schema of the dataSource.
schema: {
data: "Data",
total: "Total",
aggregates: "Aggregates",
groups: "Groups",
errors: "Errors"
}
- The complete code looks like this.
..... Other kendo grid code .....
dataSource: {
schema:
{
data: "Data",
total: "Total",
aggregates: "Aggregates",
groups: "Groups",
errors: "Errors",
...
},
transport: {
read: {
url: 'read url',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
type: 'POST'
},
create: {
url: 'create url',
dataType: "json",
contentType: 'application/json; charset=utf-8',
type: 'POST'
},
parameterMap: function (data, operation) {
return kendo.stringify(data);
}
},
error: function(e) {
console.log(e.errors); // Your error information
e.sender.cancelChanges();
},
pageSize: 20,
serverPaging: true,
serverFiltering: true,
serverSorting: true,
...
}
..... Other kendo grid code .....
- Import the KendoNET.DynamicLinq namespace.
- Use the
ToDataSourceResult extension method to apply paging, filtering, grouping, aggregating and sorting.
using KendoNET.DynamicLinq;
[WebMethod]
public static DataSourceResult<ProductViewModel> Products(int take, int skip, Filter filter, IEnumerable<Group> groups, IEnumerable<Aggregator> aggregates, IEnumerable<Sort> sorts)
{
using (var northwind = new Northwind())
{
return northwind.Products
.OrderBy(p => p.ProductID) // EF requires ordering for paging
.Select(p => new ProductViewModel // Use a view model to avoid serializing internal Entity Framework properties as JSON
{
ProductID = p.ProductID,
ProductName = p.ProductName,
UnitPrice = p.UnitPrice,
UnitsInStock = p.UnitsInStock,
Discontinued = p.Discontinued
})
.ToDataSourceResult(take, skip, filter, groups, aggregates, sorts);
}
}
or from Kendo UI request
using KendoNET.DynamicLinq;
[HttpPost]
public IActionResult Products([FromBody] DataSourceRequest requestModel)
{
using (var northwind = new Northwind())
{
var result = northwind.Products.Select(p => new ProductViewModel // Use a view model to avoid serializing internal Entity Framework properties as JSON
{
ProductID = p.ProductID,
ProductName = p.ProductName,
UnitPrice = p.UnitPrice,
UnitsInStock = p.UnitsInStock,
Discontinued = p.Discontinued
}).ToDataSourceResult(requestModel);
return Ok(result);
}
}
Asynchronous Usage
ToDataSourceResultAsync takes the same arguments, or a DataSourceRequest, plus an optional CancellationToken.
[HttpPost]
public async Task<IActionResult> Products([FromBody] DataSourceRequest requestModel, CancellationToken cancellationToken)
{
var result = await _northwind.Products
.Select(p => new ProductViewModel
{
ProductID = p.ProductID,
ProductName = p.ProductName
})
.ToDataSourceResultAsync(requestModel, cancellationToken);
return Ok(result);
}
Provider Async Support
| Async method |
EF Core |
MongoDB |
EF6 |
NHibernate |
linq2db |
CountAsync |
✓ |
✓ |
– |
– |
– |
SumAsync |
✓ |
✓ |
– |
– |
– |
AverageAsync |
✓ |
✓ |
– |
– |
– |
MinAsync |
✓ |
✓ |
– |
– |
– |
MaxAsync |
✓ |
✓ |
– |
– |
– |
ToListAsync |
✓ |
✓ |
– |
– |
– |
✓ Tested.
– Not tested yet; tests are planned.
ℹ️ A query whose provider lacks the matching async method runs synchronously, with the same results.
Date and Time Handling
Filter values are read as instants in UTC. The server's own time zone is never consulted, so the same request returns the same rows wherever the application is deployed.
| Value in the request |
Read as |
2025-11-29T16:00:00.000Z |
2025-11-29 16:00 UTC |
2025-11-30T00:00:00+08:00 |
2025-11-29 16:00 UTC |
2025-11-29 |
2025-11-29 00:00 UTC, since no zone was stated |
DateTime, DateTime?, DateTimeOffset and DateTimeOffset? columns are all supported.
Store UTC in the database and let the client convert for display. The Kendo DataSource already sends UTC, since JSON.stringify serializes a JavaScript Date to a UTC ISO string.
eq matches an exact instant
An eq filter matches only the instant supplied as the filter value. To match everything recorded on one day, filter with a gte/lt range instead. There are two ways to produce that range:
-
Let the user set it. The Grid's filter menu offers a second condition by default, so a user can choose the start and end of the day themselves. No code required.
-
Expand a single date before the request is sent. The server cannot do it for you: 2025-11-30 picked in UTC+8 arrives as 2025-11-29T16:00:00.000Z, and nothing in the request says which zone that value came from, so the day the user meant cannot be recovered. Only the client knows the zone; see Filter a Whole Day on a Date Column below.
Additional Configuration
The following configurations are optional. They can be omitted when the default Grid and server behavior is sufficient.
▸ Forward Column-Level ignoreCase to the Server
Use Filter.IgnoreCase to enable case-insensitive matching for eq, neq, contains, doesnotcontain, startswith, and endswith on string fields; leave it unset to keep the existing case-sensitive behavior. If you build DataSourceRequest/Filter manually instead of going through the Grid, just set this property directly.
When serverFiltering is enabled, the Grid column setting filterable.ignoreCase is not automatically included in the request sent to the server. Use parameterMap to copy the ignoreCase value from the column whose field matches the filter descriptor's field.
For example: