multiple orderby throws exception
See original GitHub issueOpened on SO as well: stack overflow
When trying to execute something like /odata/roles?$orderby=IsActive,Name I get the below exception.
"No generic method ‘ThenBy’ on type ‘System.Linq.Queryable’ is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. "
"System.InvalidOperationException: No generic method 'ThenBy' on type 'System.Linq.Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags) at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments) at AutoMapper.AspNet.OData.LinqExtensions.GetOrderByMethod[T](ODataQueryOptions
1 options, Expression expression)
at AutoMapper.AspNet.OData.LinqExtensions.GetQueryableExpression[T](ODataQueryOptions1 options) at AutoMapper.AspNet.OData.QueryableExtensions.GetAsync[TModel,TData](IQueryable
1 query, IMapper mapper, ODataQueryOptions1 options, HandleNullPropagationOption handleNullPropagation) at Mpi.PlanningApp.Web.Features.Roles.RolesController.Get(ODataQueryOptions
1 options) in C:\Users\A330429\Source\Repos\VVC\Planning App\src\Mpi.PlanningApp.Web\Features\Roles\RolesController.cs:line 52
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at System.Threading.Tasks.ValueTask1.get_Result() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Hellang.Middleware.ProblemDetails.ProblemDetailsMiddleware.Invoke(HttpContext context)"
Posted more code examples on stack overflow. If it’s needed, I can copy it to here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (15 by maintainers)
Top GitHub Comments
Sounds good. I will create a pr with the current fix tonight with the smaller methods you provided. I tested that, and works as it should now.
Get Outlook for Androidhttps://aka.ms/ghei36
From: Blaise Taylor notifications@github.com Sent: Friday, January 31, 2020 11:42:05 AM To: AutoMapper/AutoMapper.Extensions.OData AutoMapper.Extensions.OData@noreply.github.com Cc: Xavier tuffen_91@hotmail.com; Author author@noreply.github.com Subject: Re: [AutoMapper/AutoMapper.Extensions.OData] multiple orderby throws exception (#3)
The problem with paging is that we handle paging by generating the Queryable.Skip().Take() expression but OData also queries the result i.e. you have two records in the database. Our query skips the first one and OData’s EnableQuery skips the second one. Remove [EnableQuery()] from your controller method for paging to work. I’ll create 3 separate issues for:
We’ll only address the ThenBy() bug in this issue.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/AutoMapper/AutoMapper.Extensions.OData/issues/3?email_source=notifications&email_token=AIMW3QV5EHPTFKXHGGWD5ZLRAP573A5CNFSM4KMU3IWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKOIERA#issuecomment-580682308, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIMW3QTQBJTU5WSKQUVK4XLRAP573ANCNFSM4KMU3IWA.
This is nice. If you plan to create a PR consider shorter methods like below.
You won’t need the appyTo (you’re creating the whole lambda expression from scratch). Also no need for
ParameterExpression arg
. That already lives inGetQueryableExpression<T>
. I don’t know if OData supports sorting on child properties of references but hence theGetMemberInfoFromFullName
below.