[英]Web Api OData: A null value was detected in the items of a collection property value
I want to return following records from OData: 我想从OData返回以下记录:
Player
{
Numbers: [1, null, 3]
}
"Numbers" being a collection of nullable items (say IEnumerable). “数字”是可空项目的集合(例如IEnumerable)。 OData has a problem if any of the items in the Numbers collection is null: 如果Numbers集合中的任何一项为null,则OData会有问题:
A null value was detected in the items of a collection property value; 在集合属性值的项目中检测到空值; non-streaming instances of collection types do not support null values as items. 集合类型的非流式实例不支持将空值作为项目。
Is there a way around it? 有办法解决吗?
I'm using Web Api OData 2.2 (v3) 我正在使用Web Api OData 2.2(v3)
Thanks, Stevo 谢谢,Stevo
Try defining the Numbers
property like this: 尝试像这样定义Numbers
属性:
public IEnumerable<int?> Numbers { get; set; }
I've tested such POCO definition with some in-memory data: 我已经用一些内存数据测试了这样的POCO定义:
Numbers = new int?[]{1,null,2}
and it works fine for a V4 service written using Web API: 对于使用Web API编写的V4服务,它工作正常:
Numbers: [
1,
null,
2
],
I believe it should work also for a V3 service. 我相信它也应适用于V3服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.