正确的方法来调用嵌套从.NET的OData 4客户端展开() [英] Proper way to call nested Expand() from .NET OData 4 Client
问题描述
在基于Web API的OData的4个服务,什么是嵌套调用$从.NET客户端扩展的正确方法?我们使用的是的OData客户端生成。早在之前,WCF数据服务的OData 3服务,我们可以称之为 .Expand(客户/订单)
。在OData的4网页API,我们不能再这样做,收到你应该尝试以下 .Expand(客户/订单)
:
In an OData 4 service on Web API, what is the proper way to call nested $expand from a .NET client? We are using the OData Client Generator. Back in the prior WCF Data Services with OData 3 service we could call .Expand("Customers/Orders")
. In Web API with OData 4 we can no longer do so and receive the following should you attempt .Expand("Customers/Orders")
:
在URI中指定的查询无效。发现遍历多个导航>属性的路径。请重新表述查询,这样每个扩展路径只包含类型>段和导航属性。
The query specified in the URI is not valid. Found a path traversing multiple navigation >properties. Please rephrase the query such that each expand path contains only type >segments and navigation properties.
我们可以通过调用扩大,像这样以解决此问题: .Expand(客户($扩大=命令))
。在非嵌套$扩大情况下,我喜欢拉姆达支持像这样 .Expand(D => d.Customers)
。是否有.NET的OData 4客户以适当的方式来调用嵌套扩大无 .Expand不幸魔术字符串(客户($扩大=命令))
?如果没有,是否有像客户/订单,将工作更清洁的字符串模式?谢谢你。
Workaround
We are able to work around this by calling expand like so: .Expand("Customers($expand=Orders)")
. In non-nested $expand scenarios, I like the lambda support like so .Expand(d => d.Customers)
. Is there a proper way in .NET OData 4 client to call nested expands without the unfortunate magic string of .Expand("Customers($expand=Orders)")
? If not, is there a cleaner string pattern like "Customers/Orders" that would work? Thanks.
推荐答案
在的OData v4的,它是不是有效扩大多层次的,比如你在问题中提到的内容:.Expand(客户/订单)。我不认为客户会支持这样的API。以下是在ABNF的http://docs.oasis-open.org/odata/odata/v4.0/os/abnf/odata-abnf-construction-rules.txt:
In OData v4, it is not valid to expand multi levels, such as what you mentioned in the question: .Expand("Customers/Orders"). I dont think the client will support such API. Here is what in the ABNF http://docs.oasis-open.org/odata/odata/v4.0/os/abnf/odata-abnf-construction-rules.txt:
expand = '$expand' EQ expandItem *( COMMA expandItem )
expandItem = STAR [ ref / OPEN levels CLOSE ]
/ expandPath
[ ref [ OPEN expandRefOption *( SEMI expandRefOption ) CLOSE ]
/ count [ OPEN expandCountOption *( SEMI expandCountOption ) CLOSE ]
/ OPEN expandOption *( SEMI expandOption ) CLOSE
]
expandPath = [ qualifiedEntityTypeName "/" ]
*( ( complexProperty / complexColProperty ) "/" [ qualifiedComplexTypeName "/" ] )
navigationProperty
[ "/" qualifiedEntityTypeName ]
这篇关于正确的方法来调用嵌套从.NET的OData 4客户端展开()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!