我有一个web服务应用程序接口(使用ODataController,它有一个名为piperuns的OData端点),它接受一个可选的查询字符串(称为projectNumber),如下所示:
http://localhost:59636/piperuns?projectNumber=1
我有一个基于Simple.OData.Client的客户端,我不知道如何传递这个可选的查询字符串……我使用的是动态语法,可以使用以下语法获得piperuns (没有查询参数):
ODataFeedAnnotations annotations = new ODataFeedAnnotations();
ODataClient client = new ODataClient("http://localhost:59636/");
var x = ODataDynamic.Expression;
IEnumerable<dynamic> pipeRunsNext = await(Task<IEnumerable<Simple.OData.Client.ODataEntry>>)client
.For(x.piperuns)
.FindEntriesAsync(annotations.NextPageLink, annotations);但是,如果需要的话,我还没有找到任何关于如何包含可选查询字符串参数的信息?
谢谢!
发布于 2015-03-06 20:14:16
对于包含元数据模型属性的条件,应使用Filter子句:
IEnumerable pipeRunsNext = await client
.For(x.piperuns)
.Filter(x.projectNumber == "1")
.FindEntriesAsync(annotations.NextPageLink, annotations);但是,如果额外的子句与模型无关,我将使用接受字符串的过滤器重载:
IEnumerable pipeRunsNext = await client
.For(x.piperuns)
.Filter("projectNumber == '1'")
.FindEntriesAsync(annotations.NextPageLink, annotations);发布于 2020-05-27 16:38:43
现在,您可以使用QueryOptions传递自定义查询参数。
例如:
IEnumerable pipeRunsNext = await client
.For(x.piperuns)
.QueryOptions("projectNumber=1")
.FindEntriesAsync(annotations.NextPageLink, annotations);https://stackoverflow.com/questions/28696946
复制相似问题