【发布时间】:2019-02-15 00:10:06
【问题描述】:
通过使用表名指定 Table 属性将 Azure 函数绑定到表很简单:
[FunctionName("TableInput")]
public static void Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
[Table("MyTable")] MyTable table,
ILogger log)
{
...
}
但是如果表名是参数化的,即函数从表中读取 HTTP 请求中传递的名称:
[FunctionName("queryById")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "{tableName}")] HttpRequest req,
Binder binder,
ILogger log,
string tableName)
我想做的是使用 TableAttribute 绑定一个表:
var attributes = new Attribute[]
{
new TableAttribute(collectionName),
};
但是看起来 IBinder 接口不支持表绑定以从表中读取数据。我不能使用 CloudTable 类型的 BindAsync 来获取对 Table 的引用。我可以绑定到 TableEntity,但这仅适用于使用 IAcyncCollector 将数据插入表的目的。
有没有办法通过在运行时指定表名来将 Azure 函数动态绑定到表?
【问题讨论】:
标签: azure azure-functions azure-table-storage