首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >simple.odata.client查询参数

simple.odata.client查询参数
EN

Stack Overflow用户
提问于 2015-02-24 21:22:11
回答 2查看 2.7K关注 0票数 3

我有一个web服务应用程序接口(使用ODataController,它有一个名为piperuns的OData端点),它接受一个可选的查询字符串(称为projectNumber),如下所示:

http://localhost:59636/piperuns?projectNumber=1

我有一个基于Simple.OData.Client的客户端,我不知道如何传递这个可选的查询字符串……我使用的是动态语法,可以使用以下语法获得piperuns (没有查询参数):

代码语言:javascript
复制
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);

但是,如果需要的话,我还没有找到任何关于如何包含可选查询字符串参数的信息?

谢谢!

EN

回答 2

Stack Overflow用户

发布于 2015-03-06 20:14:16

对于包含元数据模型属性的条件,应使用Filter子句:

代码语言:javascript
复制
IEnumerable pipeRunsNext = await client
  .For(x.piperuns)
  .Filter(x.projectNumber == "1")
  .FindEntriesAsync(annotations.NextPageLink, annotations);

但是,如果额外的子句与模型无关,我将使用接受字符串的过滤器重载:

代码语言:javascript
复制
IEnumerable pipeRunsNext = await client
  .For(x.piperuns)
  .Filter("projectNumber == '1'")
  .FindEntriesAsync(annotations.NextPageLink, annotations);
票数 2
EN

Stack Overflow用户

发布于 2020-05-27 16:38:43

现在,您可以使用QueryOptions传递自定义查询参数。

例如:

代码语言:javascript
复制
IEnumerable pipeRunsNext = await client
  .For(x.piperuns)
  .QueryOptions("projectNumber=1")
  .FindEntriesAsync(annotations.NextPageLink, annotations);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28696946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档