Azure用Cosmos DB绑定功能 - 订单在以路线参数为路线时不工作
我正在尝试从特定字段订购的容器中获取项目列表。
这是我的cosmosdb与SQL查询绑定:
[FunctionName("FilterEvents")]
public static IActionResult FilterEvents(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "events/{PartitionKey}/{Order}/{SearchTerm}")] HttpRequest req,
[CosmosDB(
databaseName: Constants.DatabaseName,
collectionName: Constants.ContainerName,
ConnectionStringSetting = "CosmosDBConnectionString",
SqlQuery = "SELECT * " +
"FROM c " +
"WHERE c.email = {PartitionKey} AND CONTAINS(c.title, {SearchTerm})" +
"ORDER BY c.participantsCount {Order}"
)] IEnumerable<Event> events,
string PartitionKey,
string Order,
string SearchTerm,
ILogger log)
{
...
Console.WriteLine(PartitionKey);
Console.WriteLine(Order);
Console.WriteLine(SearchTerm);
}
当我使用此参数调用此API时:
https://../api/events/ [email&nbsp; procearted] /asc/asc/event
以下错误:
System.Private.CoreLib: Exception while executing function: FilterEvents.
Microsoft.Azure.WebJobs.Host: Exception binding parameter 'events'.
Microsoft.Azure.DocumentDB.Core: Message:
{
"errors":[
{
"severity":"Error",
"location": {
"start":101,
"end":107},
"code":"SC1001",
"message":"Syntax error, incorrect syntax near '@Order'."
}
]
}
[2022-07-07T13:49:53.666Z] ActivityId: 2a1a4919-f6e9-4b10-81b3-2ff2aa9d0159, Microsoft.Azure.Documents.Common/2.14.0, Windows/10.0.22621 documentdb-netcore-sdk/2.13.1.
我
收到 ,从c中选择 * c.email = {partitionKey}并包含(c.Title,{searchTerm})
并使用相同的URL参数调用, https://.. //../api/events/ [email&nbsp; procearted] /asc/asc/event
我什至可以看到在console中打印的值
Console.WriteLine(PartitionKey); // [email protected]
Console.WriteLine(Order); // ASC
Console.WriteLine(SearchTerm); // event
:或“ desc”代替 {order}
,事情只是工作预计,
我找不到任何建议
。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来不受支持。如果您查看实现在这里,它正在转换查询参数到SQL参数:
这与子句的顺序无法使用。
或者,您可以使用 documentclient 绑定,但是您必须自己编写查询:
老实说,不确定是否会更糟。如果您知道查询不会返回太多项目,则可以通过子句对该订单的默认值进行编程恢复:
它将允许您保留现有的实现。
It doesn't looks like it is supported. If you look at the implementation here, it is converting the query parameters into SQL parameters:
This won't work with ORDER BY clause.
Alternatively, you could use the DocumentClient binding but then you'll have to write the query yourself:
To be honest, not sure if it worse it. If you know the query won't returned too many items, you could have a default value for the order by clause and revert it programmatically:
It will allow you to keep your existing implementation.