Eri*_*ing 4 azure azure-functions azure-cosmosdb
我有一个Azure功能,使用该DocumentDB属性连接到Cosmos DB.我正在使用Azure函数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);
}
Run Code Online (Sandbox Code Playgroud)
我希望能够传递属性的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);
}
Run Code Online (Sandbox Code Playgroud)
我只看到一个例子这样做,并报告它应该工作.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查询运行它?
您需要引用NuGet包的1.1.0-beta版本Microsoft.Azure.WebJobs.Extensions.DocumentDB(或更高版本).
在该版本中SqlQuery是DocumentDB属性的有效参数.你为我编译代码,如果我$在select字符串前删除符号:
[DocumentDB("FunctionJunctionDemo", "Demo", SqlQuery = "select * from c where c.Id = {Id}")]
Run Code Online (Sandbox Code Playgroud)
你不需要$- 它用于C#中的字符串插值,而不是你想在这里做的事情.
| 归档时间: |
|
| 查看次数: |
528 次 |
| 最近记录: |