RadzenDataGrid generating wrong filter for enums when using oData. #901

Closed
opened 2026-01-29 17:46:02 +00:00 by claunia · 1 comment
Owner

Originally created by @Molinware on GitHub (Jun 20, 2023).

Describe the bug
Using the RadzenDataGrid to filter an Enumerator column causes the wrong filter to be generated.
Example:

public enum StatusEnum
{
    Active,
    Inactive
}

public UserDto
{
    public Guid Id { get; set; }
    public StatusEnum Status { get; set; }
}

The filter will be Status eq '0' making the following error happen in the backend:

{"error":{"code":"","message":"The query specified in the URI is not valid. The string '0' is not a valid enumeration type constant.","details":[],"innererror":{"message":"The string '0' is not a valid enumeration type constant.","type":"Microsoft.OData.ODataException","stacktrace":"   at Microsoft.OData.UriParser.MetadataBindingUtils.ConvertToTypeIfNeeded(SingleValueNode source, IEdmTypeReference targetTypeReference)\r\n   at Microsoft.OData.UriParser.BinaryOperatorBinder.PromoteOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& left, SingleValueNode& right, TypeFacetsPromotionRules facetsPromotionRules)\r\n   at Microsoft.OData.UriParser.ODataUriResolver.PromoteBinaryOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& leftNode, SingleValueNode& rightNode, IEdmTypeReference& typeReference)\r\n   at Microsoft.OData.UriParser.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n   at Microsoft.OData.UriParser.MetadataBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n   at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)\r\n   at Microsoft.OData.UriParser.FilterBinder.BindFilter(QueryToken filter)\r\n   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()\r\n   at Microsoft.AspNetCore.OData.Query.FilterQueryOption.get_FilterClause()\r\n   at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n   at Microsoft.AspNetCore.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings)\r\n   at Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\r\n   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext)"}}}

Expected behavior
The filter that should be generated is Status eq 'Active' or Status eq 0.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome
  • Version: 114.0.5735.134
Originally created by @Molinware on GitHub (Jun 20, 2023). **Describe the bug** Using the RadzenDataGrid to filter an Enumerator column causes the wrong filter to be generated. Example: ``` public enum StatusEnum { Active, Inactive } public UserDto { public Guid Id { get; set; } public StatusEnum Status { get; set; } } ``` The filter will be **_Status eq '0'_** making the following error happen in the backend: ``` {"error":{"code":"","message":"The query specified in the URI is not valid. The string '0' is not a valid enumeration type constant.","details":[],"innererror":{"message":"The string '0' is not a valid enumeration type constant.","type":"Microsoft.OData.ODataException","stacktrace":" at Microsoft.OData.UriParser.MetadataBindingUtils.ConvertToTypeIfNeeded(SingleValueNode source, IEdmTypeReference targetTypeReference)\r\n at Microsoft.OData.UriParser.BinaryOperatorBinder.PromoteOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& left, SingleValueNode& right, TypeFacetsPromotionRules facetsPromotionRules)\r\n at Microsoft.OData.UriParser.ODataUriResolver.PromoteBinaryOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& leftNode, SingleValueNode& rightNode, IEdmTypeReference& typeReference)\r\n at Microsoft.OData.UriParser.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n at Microsoft.OData.UriParser.MetadataBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.OData.UriParser.FilterBinder.BindFilter(QueryToken filter)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()\r\n at Microsoft.AspNetCore.OData.Query.FilterQueryOption.get_FilterClause()\r\n at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n at Microsoft.AspNetCore.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings)\r\n at Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext)"}}} ``` **Expected behavior** The filter that should be generated is **_Status eq 'Active'_** or **Status eq 0**. **Desktop (please complete the following information):** - OS: Windows 11 - Browser: Chrome - Version: 114.0.5735.134
Author
Owner

@enchev commented on GitHub (Jun 26, 2023):

Hey @Molinware,

You might need to check this thread: https://github.com/OData/AspNetCoreOData/issues/422 - in short you will need StringAsEnumResolver.

@enchev commented on GitHub (Jun 26, 2023): Hey @Molinware, You might need to check this thread: https://github.com/OData/AspNetCoreOData/issues/422 - in short you will need StringAsEnumResolver.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#901