我有一个Web服务API(带有OData端点,名为piperuns,使用ODataController),它接受一个可选的查询字符串(称为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);
但是,如果需要,我还没有找到有关如何包含我的可选查询字符串参数的任何信息?
谢谢!
答案 0 :(得分:2)
对于包含元数据模型属性的条件,您应该使用Filter子句:
IEnumerable pipeRunsNext = await client
.For(x.piperuns)
.Filter(x.projectNumber == "1")
.FindEntriesAsync(annotations.NextPageLink, annotations);
但是,如果extra子句与模型无关,我会使用带有字符串的Filter重载:
IEnumerable pipeRunsNext = await client
.For(x.piperuns)
.Filter("projectNumber == '1'")
.FindEntriesAsync(annotations.NextPageLink, annotations);
答案 1 :(得分:0)
现在,您可以使用QueryOptions
来传递自定义查询参数。
例如
IEnumerable pipeRunsNext = await client
.For(x.piperuns)
.QueryOptions("projectNumber=1")
.FindEntriesAsync(annotations.NextPageLink, annotations);