Approved
Last Updated: 12 Nov 2019 13:06 by ADMIN
Alessandro
Created on: 08 Mar 2019 13:07
Category: UI for ASP.NET MVC
Type: Feature Request
2
The "ToDataSourceResult" function replaces an existing sort on IQueryable with a default one if the "Sorts" list property is empty in the DataSourceRequest

The "CreateDataSourceResult" function verifies if the given DataSourceRequest "Sorts" list is empty and if the IQueryable provider is Entity Framework. If both are true, it adds a default OrderBy to the query on the first sortable property. This makes sense as EF must be ordered before skipping items.

The following statement checks the given DataSourceRequest and IQueryable:

if (!sort.Any() && queryable.Provider.IsEntityFrameworkProvider())

{...}

This leads to unwanted behavior if the query is already sorted on the server and the corresponding SortDescriptor is removed from the "Sorts" list. This is needed if we want to sort on a viewmodel property that doesn't exist on the EF model.

An additional check should be done on IQueryable to see if it is already ordered to avoid replacing the existing OrderBy with a default one.

if (!sort.Any() && queryable.Provider.IsEntityFrameworkProvider() && queryable.Expression.Type != typeof(IOrderedQueryable<TModel>))
{...}

 

 

 

1 comment
ADMIN
Joana
Posted on: 15 Mar 2019 08:12
Hi Alessandro,

Thank you for digging into the DataSourceResult and for providing such detailed information on the request.

The request will be further updated once it's evaluated by our development team and is planned in our RoadMap.

Regards,
Joana
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.