sorting failed on varchar field
when the sort filed type is varchar,the sorting will fail into exception. but success when the field type is number or datetime
@wensaint Could you please share more information on the Exception, stack trace, your queried object and client side query if any involved.
2019-08-29 18:09:19.602 +08:00 [Error] syslog: sysRole
DynamicQueryBuilder.DynamicQueryBuilderExceptions+DynamicQueryException: DynamicQueryBuilder has encountered an unhandled exception ---> System.ArgumentException: Incorrect number of arguments supplied for call to method 'System.Linq.IOrderedQueryable1[Wensaint.BaseApp.Model.sysRole] OrderBy[sysRole,String](System.Linq.IQueryable1[Wensaint.BaseApp.Model.sysRole], System.Linq.Expressions.Expression1[System.Func2[Wensaint.BaseApp.Model.sysRole,System.String]])'
Parameter name: method
at System.Dynamic.Utils.ExpressionUtils.ValidateArgumentCount(MethodBase method, ExpressionType nodeKind, Int32 count, ParameterInfo[] pis)
at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0, Expression arg1, Expression arg2)
at DynamicQueryBuilder.Visitors.OrderFunctionVisitor.IterateOrderOptions(Boolean& isPreOrdered, Expression& currentNode)
at DynamicQueryBuilder.Visitors.OrderFunctionVisitor.ApplyOrders()
at DynamicQueryBuilder.ExpressionBuilder.ApplyFilters(IQueryable currentSet, DynamicQueryOptions dynamicQueryOptions)
--- End of inner exception stack trace ---
at DynamicQueryBuilder.ExpressionBuilder.ApplyFilters(IQueryable currentSet, DynamicQueryOptions dynamicQueryOptions)
at DynamicQueryBuilder.ExpressionBuilder.ApplyFilters[T](IQueryable`1 currentSet, DynamicQueryOptions dynamicQueryOptions)
I have fixed the problem by modify the follow file.
File: OrderFunctionVisitor.cs Line:84-115
private void IterateOrderOptions(ref bool isPreOrdered, ref Expression currentNode) { foreach (OrderOptionDetails orderOpts in _orderOptionDetails) { //if (!_usesCaseInsensitiveSource && orderOpts.ParameterExpression.Type == typeof(string)) //{ // currentNode = Expression.Call( // GetSortMethod( // orderOpts.Direction, // orderOpts.ParameterExpression.Type, // ref isPreOrdered, // orderOpts.CaseSensitive), // currentNode, // Expression.Quote(orderOpts.Expression), // Expression.Constant(orderOpts.CaseSensitive // ? StringComparer.InvariantCulture // : StringComparer.InvariantCultureIgnoreCase)); //} //else //{ currentNode = Expression.Call( GetSortMethod( orderOpts.Direction, orderOpts.ParameterExpression.Type, ref isPreOrdered, orderOpts.CaseSensitive), currentNode, Expression.Quote(orderOpts.Expression)); //} } }
@cyilcode please check and merge
@cyilcode please double check in time. if there is no bug, update and publish it.
@wensaint The version 1.0.3-pre has the fix for this issue already. I am currently testing the new version. I'll be providing a release this Sunday.
@cyilcode ok,thank u. I am waiting for the new version.