【发布时间】:2016-12-02 03:13:09
【问题描述】:
我创建了一个 Web API OData v4 服务。我正在尝试创建一个绑定函数,该函数的 TimeSpan 参数具有在 OData 控制器中定义的签名,类似于以下内容:
public IQueryable<ProductionRecordDTO> GetProduction(
[FromODataUri]DateTimeOffset startDate,
[FromODataUri]DateTimeOffset endDate,
[FromODataUri]TimeSpan sampleInterval)
在 OData 模型构建器中配置如下:
var getProduction = builder.EntitySet<ProductDTO>("Products").EntityType.Collection.Function("GetProduction");
getProduction.Namespace = "ProductsService";
getProduction.ReturnsCollection<ProductionRecordDTO>();
getProduction.Parameter<DateTimeOffset>("StartDate");
getProduction.Parameter<DateTimeOffset>("EndDate");
getProduction.Parameter<TimeSpan>("SampleInterval");
运行时,模型似乎已正确创建,元数据描述显示“SampleInterval”已正确定义为 Edm.Duration 类型。
当我尝试使用如下 URL 调用此方法时:
http://dev-pc/odata/Products/ProductsService.GetProduction(StartDate=2014-01-01T00:00:00Z, EndDate=2017-01-01T00:00:00Z, SampleInterval=P1Y)
抛出 ODataException 并显示消息“SampleInterval=P1Y”不在范围内。我给它的每个 ISO 8601 持续时间格式变体都是如此。
使用:
- Microsoft.OData.Core - v6.15.0
- Microsoft.AspNet.OData - v5.9.1
我们将不胜感激。
【问题讨论】:
标签: c# .net asp.net-web-api2 odata