使用 Azure 函数的事件网格触发器时,我可以访问绑定表达式中的数据属性吗?
When using Event Grid trigger for Azure Function can I access data properties in binding expressions?
我正在尝试编写一个具有事件网格触发器和 CosmosDB 输入绑定的 Azure 函数。我想使用触发事件网格事件中的数据来定义查询的一部分,因此我只从 Cosmos 获取我需要的文档。
示例事件数据:
{
"referenceId": "id-43"
}
C# 中的当前函数定义:
public static void Run(
[EventGridEvent] @event,
[CosmosDB(
databaseName: "%DatabaseName%",
collectionName: "%CollectionName%",
ConnectionStringSetting = "CosmosConnectionString",
SqlQuery = "SELECT * FROM root WHERE root.otherDocId = '{data.referenceId}'"
)] IEnumerable<Document> documents,
ILogger logger)
{
// Function Body
}
目前,当我尝试 post 时遇到错误 Error while accessing 'referenceId': property does not exist.
的问题。有没有一种方法可以将数据用作 SQL 查询中绑定表达式的一部分?
编辑:
我知道可以绑定数据属性,因为我们有另一个绑定到 CosmosDB
属性的 Id
和 PartitionKey
属性的函数。例如:
public static void Run(
[EventGridEvent] @event,
[CosmosDB(
databaseName: "%DatabaseName%",
collectionName: "%CollectionName%",
ConnectionStringSetting = "CosmosConnectionString",
Id = "{data.idProperty}",
PartitionKey = "{data.partitionKeyProperty}"
)] Document document,
ILogger logger)
{
// Function Body
}
不幸的是,我无法在此实例中使用分区键来过滤文档,它必须通过 SQL 查询。
进一步挖掘后,这似乎是一个已知问题,从 azure-webjobs-sdk-extensions
GitHub 页面上的这个问题可以看出:https://github.com/Azure/azure-webjobs-sdk-extensions/issues/595
SqlQuery
属性 上有一个特定属性控制如何处理参数绑定,但不适用于嵌套属性。大多数人在使用 Http 触发器的查询参数时会遇到此问题,但同样的问题也适用于此实例。
我正在尝试编写一个具有事件网格触发器和 CosmosDB 输入绑定的 Azure 函数。我想使用触发事件网格事件中的数据来定义查询的一部分,因此我只从 Cosmos 获取我需要的文档。
示例事件数据:
{
"referenceId": "id-43"
}
C# 中的当前函数定义:
public static void Run(
[EventGridEvent] @event,
[CosmosDB(
databaseName: "%DatabaseName%",
collectionName: "%CollectionName%",
ConnectionStringSetting = "CosmosConnectionString",
SqlQuery = "SELECT * FROM root WHERE root.otherDocId = '{data.referenceId}'"
)] IEnumerable<Document> documents,
ILogger logger)
{
// Function Body
}
目前,当我尝试 post 时遇到错误 Error while accessing 'referenceId': property does not exist.
的问题。有没有一种方法可以将数据用作 SQL 查询中绑定表达式的一部分?
编辑:
我知道可以绑定数据属性,因为我们有另一个绑定到 CosmosDB
属性的 Id
和 PartitionKey
属性的函数。例如:
public static void Run(
[EventGridEvent] @event,
[CosmosDB(
databaseName: "%DatabaseName%",
collectionName: "%CollectionName%",
ConnectionStringSetting = "CosmosConnectionString",
Id = "{data.idProperty}",
PartitionKey = "{data.partitionKeyProperty}"
)] Document document,
ILogger logger)
{
// Function Body
}
不幸的是,我无法在此实例中使用分区键来过滤文档,它必须通过 SQL 查询。
进一步挖掘后,这似乎是一个已知问题,从 azure-webjobs-sdk-extensions
GitHub 页面上的这个问题可以看出:https://github.com/Azure/azure-webjobs-sdk-extensions/issues/595
SqlQuery
属性 上有一个特定属性控制如何处理参数绑定,但不适用于嵌套属性。大多数人在使用 Http 触发器的查询参数时会遇到此问题,但同样的问题也适用于此实例。