通过枚举的智力值的OData V4 +的WebAPI过滤器? [英] OData V4 + WebAPI Filter by Int Value of Enum?

查看:197
本文介绍了通过枚举的智力值的OData V4 +的WebAPI过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OData的V4具有枚举支持,但您似乎只命名空间进行搜索。一个人如何现在的价值,而不是文本重新presentation搜索?

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?

在的ODATA可以查询 $过滤器=状态EQ 35 ,其中 35 是<$ C V3 $ C>完整在枚举。这种方法将工作,即使那场是在数据模型中的枚举字段。

In V3 of odata you could query for $filter=Status eq 35, where 35 is Complete in the enum. This method would work, even if that field was an enum field in the data model.

现在这种方法在V4失败,而不需要用enum的文本再presentation的命名空间。

Now this method fails in V4, instead requiring the namespace with text representation of the enum.

我想要得到的V3支持,而不必失去ODATA V4的其他功能再次合作。由枚举项的int值搜索似乎比搜索文本更可靠。较早的ODATA客户端(如剑道)不支持通过一个文本枚举过滤方法。

I want to get the V3 support working again without having to lose the other features of odata V4. Searching by the int value for the enum item seems more reliable than searching for text. Older odata clients (such as kendo) don't support a by-text enum filtering method.

推荐答案

要做到这一点在的OData v4的,我们可以在最初的WebAPI配置使枚举prefixFree,所以我们没有写完整的枚举命名空间preFIX:

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);
    // ...
}

那么,我们就可以通过过滤字符串或int值的枚举:

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

$filter=Status eq 'single'

$filter=Status eq 1

希望这有助于。

这篇关于通过枚举的智力值的OData V4 +的WebAPI过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆