locked
Web API - OData v4 - exception when using enum filter RRS feed

  • Question

  • User-857445687 posted

    Hi,

    I'm getting an "Type provided must be an Enum" exception, when using an enum filter.

    Note that I have no issues when adding, updating entities with enums. Only filtering seems broken (for me).

    I have also enabled the enum prefix free option: config.EnableEnumPrefixFree(enumPrefixFree: true);

    E.g. odata/MyExamples?$filter=MyEnumProp+eq+'One'

    I'm using: VS 2013,

    Web API 2.2 for OData v4.0 5.6.0-beta1 (same issue with "OData v4.0 5.5.1")

    Web API 2.2 5.2.3

    Entity Framework 6

     "error":{
        "code": "",
        "message": "An error has occurred.",
        "innererror": {
            "message": "Der angegebene Typ muss eine Enumeration sein.\r\n Parametername: enumType",
            "type": "System.ArgumentException",
            "stacktrace": "
                bei System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)\r\n
                bei System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)\r\n
                bei System.Enum.Parse(Type enumType, String value)\r\n
                bei System.Web.OData.Query.Expressions.FilterBinder.BindConstantNode(ConstantNode constantNode)\r\n
                bei System.Web.OData.Query.Expressions.FilterBinder.Bind(QueryNode node)\r\n
                bei System.Web.OData.Query.Expressions.FilterBinder.BindBinaryOperatorNode(BinaryOperatorNode binaryOperatorNode)\r\n
                bei System.Web.OData.Query.Expressions.FilterBinder.Bind(QueryNode node)\r\n
                bei System.Web.OData.Query.Expressions.FilterBinder.BindExpression(SingleValueNode expression, RangeVariable rangeVariable, Type elementType)\r\n
                bei System.Web.OData.Query.Expressions.FilterBinder.Bind(FilterClause filterClause, Type filterType, IEdmModel model, IAssembliesResolver assembliesResolver, ODataQuerySettings querySettings)\r\n
                bei System.Web.OData.Query.FilterQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings, IAssembliesResolver assembliesResolver)\r\n
                bei System.Web.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n
                bei System.Web.OData.EnableQueryAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)\r\n
                bei System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n
                bei System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n
                bei System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)\r\n
                ...            
        }
      }

    Code:

    [ODataRoute, EnableQuery]
    public IQueryable<MyExampleEntity> Get()
    {
        return _db.MyExamples;
    } 
      
    public class MyExampleEntity
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public Guid Id { get; set; }
    
        public MyExampleEnum? MyEnumProp { get; set; }
    }
    
    public enum MyExampleEnum
    {
        One,
        Two
    }

    Is this a bug?

    By the way: is this the correct forum for this issue? Dunno if I should ask at https://github.com/OData/WebApi instead.

    Best regards,

    Kasimier Buchcik

    Tuesday, May 5, 2015 2:04 PM

All replies