【发布时间】:2017-08-02 21:23:23
【问题描述】:
我有一个使用 DocumentDB 属性连接到 Cosmos DB 的 Azure 函数。我正在使用 Azure Functions for Visual Studio 2017 工具。这是简单的函数
[FunctionName("DocumentDbGet")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get")]HttpRequestMessage req, TraceWriter log,
[DocumentDB("FunctionJunctionDemo", "Demo")]IEnumerable<DemoModel> items)
{
//Can perform operations on the "items" variable, which will be the result of the table/collection you specify
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
var item = items.Where(x => x.FirstName == name);
return req.CreateResponse(HttpStatusCode.OK);
}
我希望能够将SqlQuery 作为DocumentDB 属性的参数之一传递,如下所示:
[FunctionName("DocumentDbGet")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get")]HttpRequestMessage req, TraceWriter log,
[DocumentDB("FunctionJunctionDemo", "Demo", SqlQuery = $"select * from c where c.Id = {Id}")]IEnumerable<DemoModel> items)
{
//Can perform operations on the "items" variable, which will be the result of the table/collection you specify
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
var item = items.Where(x => x.FirstName == name);
return req.CreateResponse(HttpStatusCode.OK);
}
我只看到 1 个示例执行此操作,并报告说它应该有效。 https://github.com/Azure/Azure-Functions/issues/271
我收到的“错误”是它没有将任何名为 SqlQuery 的东西识别为可能的参数。
我查看了 Azure 函数输入绑定的文档
https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-documentdb#input-sample-with-multiple-documents 显示 function.json 文件中包含 sqlQuery 属性的输出。那是怎么进去的?
如果无法在 DocumentDB 属性中传入 SqlQuery,那么预先过滤结果以避免返回整个集合然后通过 LINQ 查询运行它的最佳做法是什么?
【问题讨论】:
标签: azure azure-cosmosdb azure-functions