繁体   English   中英

Azure Functions SDK

[英]Azure Functions SDK

升级到1.0.1 CLI工具而没有任何代码更改后,我突然开始出现以下错误:

ResizeImage: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ResizeImage'. 
Microsoft.Azure.WebJobs.Extensions.DocumentDB:
 'Id' is required when binding to a DocumentClient property.

如下代码:

[FunctionName(nameof(ResizeImage))]
public static async Task RunAsync([BlobTrigger("profile-pictures/{name}")] CloudBlockBlob myBlob, string name, [DocumentDB(databaseName: "x", collectionName: "UserProfile", CreateIfNotExists = true)] DocumentClient client, [Blob("profile-pictures/resized-{name}", FileAccess.ReadWrite)] CloudBlockBlob resizedBlob, TraceWriter log)

我以为id是可选的? 至少文档就是这样说的。

根据文档:

不能同时指定属性id和sqlQuery。 如果未设置id或sqlQuery,则将检索整个集合。

生成的json:

{
  "bindings": [
    {
      "type": "blobTrigger",
      "path": "profile-pictures/{name}",
      "direction": "in",
      "name": "myBlob"
    },
    {
      "type": "documentDB",
      "databaseName": "x",
      "collectionName": "UserProfile",
      "createIfNotExists": true,
      "direction": "out",
      "name": "client"
    },
    {
      "type": "blob",
      "path": "profile-pictures/resized-{name}",
      "direction": "inout",
      "name": "resizedBlob"
    }
  ],
  "disabled": false,
  "scriptFile": "..\\X.Functions.dll",
  "entryPoint": "X.Functions.ResizeImage.RunAsync"
}

我正在使用1.0.0 SDK

我以为id是可选的? 至少文档就是这样说的。

是的,id是可选的。 但是根据Azure Functions Cosmos DB的文档绑定 我们需要使用IEnumerable <dynamic>作为绑定类型。 请按以下方式更改您的代码。

[DocumentDB(...)] IEnumerable<dynamic> documents

您将从集合中获取所有文档。 我对其进行了测试,结果对我而言效果很好。

另外,如果要从DocumentDB获取数据,则应将方向更改为in。

"direction": "in"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM