使用最新的 Microsoft.AspNetCore.OData 8.0.0-rc3。
services.AddControllers()
.AddOData(opt => opt.Count().Filter().Expand().Select().OrderBy().SetMaxTop(100)
.AddModel(string.Empty, GetEdmModel(),
builder =>
{
builder.AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataUriResolver), sp => new StringAsEnumResolver() { EnableCaseInsensitive = true });
})
.Conventions.Add(new OdataConvention()))
Run Code Online (Sandbox Code Playgroud)
使用上面的代码来配置StringAsEnumResolver,我仍然无法使用字符串来过滤枚举。我在互联网上搜索过但无济于事。
我缺少什么?
错误来自$filter=contactType eq 'person':
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. The string 'person' is not a valid enumeration type constant.",
"details": [
],
"innererror": {
"message": "The string 'person' is not a valid enumeration type constant.",
"type": "Microsoft.OData.ODataException",
"stacktrace": " …Run Code Online (Sandbox Code Playgroud)