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>))
{...}