DynamicQueryBuilder icon indicating copy to clipboard operation
DynamicQueryBuilder copied to clipboard

sorting failed on varchar field

Open wensaint opened this issue 6 years ago • 6 comments

when the sort filed type is varchar,the sorting will fail into exception. but success when the field type is number or datetime

wensaint avatar Aug 06 '19 09:08 wensaint

@wensaint Could you please share more information on the Exception, stack trace, your queried object and client side query if any involved.

cyilcode avatar Aug 06 '19 10:08 cyilcode

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)

wensaint avatar Aug 29 '19 10:08 wensaint

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

wensaint avatar Sep 09 '19 02:09 wensaint

@cyilcode please double check in time. if there is no bug, update and publish it.

wensaint avatar Sep 12 '19 01:09 wensaint

@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 avatar Sep 13 '19 12:09 cyilcode

@cyilcode ok,thank u. I am waiting for the new version.

wensaint avatar Sep 17 '19 03:09 wensaint