You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For various reasons, I want to pass an IQueryable containing an OrderBy statement to DataSourceLoader.Load.
Basicallly something like
varitems=db.Items.OrderBy(i =>i.Name).Select(i =>i.Name);// where loadOptions.Sort = new SortingInfo[0];varresult=DataSourceLoader.Load(items,loadOptions);
When working with version 2.4.4 Load did honor the OrderBy, but 2.5.0 ignores it completely (both ignore it actually). So, how I go with custom sorting in this case?
Perhaps I'm wrong, but Select in this case is client side and applying sort and/or filter on it, would cause a problem because it will have to fetch all the data from the database first.
Thank you for the update. Now I better understand the issue. You need to sort original items by Name and then project them so that Name becomes LowercaseName.
I just posted a comment about DTO mapping. Please review it and let me know if such a feature would address your requirements. In the interim, check if you can use the workaround suggested in #378 (comment).
Activity
AlekseyMartynov commentedon Oct 1, 2019
You can use the DataSourceLoadOptionsBase.DefaultSort property or build a custom sort list:
The following support ticket may be relevant:
MihaMarkic commentedon Oct 2, 2019
@AlekseyMartynov Well, that most probably won't work if I were to use a client side projection.
AlekseyMartynov commentedon Oct 2, 2019
Would you please add a code sample to illustrate what exactly won't work?
Internally,
DataSourceLoaderbuilds a LINQ expression by appendingWhere,OrderBy, etc to the source query. For example:Subsequent
OrderBycancels previousOrderBy. To keep sorting byName, you can useDefaultSortor modifySortas suggested in #388 (comment).Alternatively, we can add a boolean option to prevent any sort inside
DataSourceLoaderwhen the source query is pre-sorted.MihaMarkic commentedon Oct 18, 2019
@AlekseyMartynov Sorry for the delay
Imagine a projection to a
Perhaps I'm wrong, but Select in this case is client side and applying sort and/or filter on it, would cause a problem because it will have to fetch all the data from the database first.
AlekseyMartynov commentedon Oct 18, 2019
Thank you for the update. Now I better understand the issue. You need to sort original items by
Nameand then project them so thatNamebecomesLowercaseName.I just posted a comment about DTO mapping. Please review it and let me know if such a feature would address your requirements. In the interim, check if you can use the workaround suggested in #378 (comment).