OData V4 + WebAPI Filter by Int Value of Enum?

前端 未结 2 1824
南旧
南旧 2020-12-31 20:12

OData V4 has enum support but it appears you have to search by the namespace only. How does one now search by the value instead of the text representation?

In V3 of

2条回答
  •  北海茫月
    2020-12-31 20:40

    to do that in OData v4, we can enable the EnumPrefixFree in the initial webapi configuration, so we dont have to write the full enum namespace as prefix :

    public static void Register(HttpConfiguration config)
    {
        // ...
        config.EnableEnumPrefixFree(enumPrefixFree: true);
        config.MapODataServiceRoute("odata", "odata", YourEdmModem);
        // ...
    }
    

    then, we can filter any enum by String or Int value :

    $filter=Status eq 'single'
    

    or

    $filter=Status eq 1
    

    hope this helps.

提交回复
热议问题