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
Cursor pagination with EF (using AddDbContextCursorPagingProvider) and enum-based sorting should be supported, as enums are considered straightforward types.
What is actually happening?
ICursorKeySerializer and ExpressionHelpers appear to be incompatible with enums (IComparable), while they are compatible with types that support IComparable<T>.
The errors do not appear in the initial query, but rather in the subsequent query when the "after" parameter is applied.
Relevant log output
Expression of type Host.SomeEnum cannot be used for parameter of type System.Object of method Int32 CompareTo(System.Object) (Parameter arg0).
at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)\r\n
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression arg0)\r\n
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)\r\nat GreenDonut.Data.Expressions.ExpressionHelpers.BuildWhereExpression[T](ReadOnlySpan`1 keys, Cursor cursor, Boolean forward)\r\nat HotChocolate.Data.Pagination.EfQueryableCursorPagingHandler`1.SliceAsync(IResolverContext context, IQueryableExecutable`1 executable, CursorPagingArguments arguments)\r\nat HotChocolate.Types.Pagination.CursorPagingHandler.HotChocolate.Types.Pagination.IPagingHandler.SliceAsync(IResolverContext context, Object source)\r\nat HotChocolate.Types.Pagination.PagingMiddleware.InvokeAsync(IMiddlewareContext context)\r\nat HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\nat HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)""The LINQ expression 'DbSet<User>() .OrderBy(u => u.SkillType) .Where(u => u.SkillType.CompareTo((object)__value_0) > 0)' could not be translated. Additional information: Translation of method 'System.Enum.CompareTo' failed. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'."
Additional context
Please refer to the repro README for a proof-of-concept solution. Is this a valid direction to proceed? Additionally, could this behavior be considered a bug, or is it an intentional design decision?
The text was updated successfully, but these errors were encountered:
Product
Green Donut
Version
15.1.1
Link to minimal reproduction
https://github.com/marcin-janiak/cursor-based-pagination-with-enum-sorting/tree/main
Steps to reproduce
Clone, run and observe console
What is expected?
Cursor pagination with EF (using AddDbContextCursorPagingProvider) and enum-based sorting should be supported, as enums are considered straightforward types.
What is actually happening?
ICursorKeySerializer and ExpressionHelpers appear to be incompatible with enums (
IComparable
), while they are compatible with types that supportIComparable<T>
.The errors do not appear in the initial query, but rather in the subsequent query when the "after" parameter is applied.
Relevant log output
Additional context
Please refer to the repro README for a proof-of-concept solution. Is this a valid direction to proceed? Additionally, could this behavior be considered a bug, or is it an intentional design decision?
The text was updated successfully, but these errors were encountered: