Уреди

Делите путем


Azure Tables bindings for Azure Functions

Azure Functions integrates with Azure Tables via triggers and bindings. Integrating with Azure Tables allows you to build functions that read and write data using Azure Cosmos DB for Table and Azure Table Storage.

Action Type
Read table data in a function Input binding
Allow a function to write table data Output binding

Install extension

The extension NuGet package you install depends on the C# mode you're using in your function app:

Functions execute in an isolated C# worker process. To learn more, see Guide for running C# Azure Functions in an isolated worker process.

The process for installing the extension varies depending on the extension version:

This version introduces the ability to connect using an identity instead of a secret. For a tutorial on configuring your function apps with managed identities, see the creating a function app with identity-based connections tutorial.

This version allows you to bind to types from Azure.Data.Tables. It also introduces the ability to use Azure Cosmos DB for Table.

This extension is available by installing the Microsoft.Azure.Functions.Worker.Extensions.Tables NuGet package into a project using version 5.x or higher of the extensions for blobs and queues.

Using the .NET CLI:

# Install the Azure Tables extension
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Tables --version 1.0.0

# Update the combined Azure Storage extension (to a version which no longer includes Azure Tables)
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Storage --version 5.0.0

Note

Azure Blobs, Azure Queues, and Azure Tables now use separate extensions and are referenced individually. For example, to use the triggers and bindings for all three services in your .NET isolated-process app, you should add the following packages to your project:

Previously, the extensions shipped together as Microsoft.Azure.Functions.Worker.Extensions.Storage, version 4.x. This same package also has a 5.x version, which references the split packages for blobs and queues only. When upgrading your package references from older versions, you may therefore need to additionally reference the new Microsoft.Azure.Functions.Worker.Extensions.Tables NuGet package. Also, when referencing these newer split packages, make sure you are not referencing an older version of the combined storage package, as this will result in conflicts from two definitions of the same bindings.

If you're writing your application using F#, you must also configure this extension as part of the app's startup configuration. In the call to ConfigureFunctionsWorkerDefaults() or ConfigureFunctionsWebApplication(), add a delegate that takes an IFunctionsWorkerApplication parameter. Then within the body of that delegate, call ConfigureTablesExtension() on the object:

let hostBuilder = new HostBuilder()
hostBuilder.ConfigureFunctionsWorkerDefaults(fun (context: HostBuilderContext) (appBuilder: IFunctionsWorkerApplicationBuilder) ->
    appBuilder.ConfigureTablesExtension() |> ignore
) |> ignore

Install bundle

The Azure Tables bindings are part of an extension bundle, which is specified in your host.json project file. You may need to modify this bundle to change the version of the bindings, or if bundles aren't already installed. To learn more, see extension bundle.

This version introduces the ability to connect using an identity instead of a secret. For a tutorial on configuring your function apps with managed identities, see the creating a function app with identity-based connections tutorial.

You can add this version of the extension from the extension bundle v3 by adding or replacing the following code in your host.json file:

{
    "version": "2.0",
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[3.3.0, 4.0.0)"
    }
}

Binding types

The binding types supported for .NET depend on both the extension version and C# execution mode, which can be one of the following:

An isolated worker process class library compiled C# function runs in a process isolated from the runtime.

Choose a version to see binding type details for the mode and version.

The isolated worker process supports parameter types according to the tables below. Support for binding to types from Azure.Data.Tables is in preview.

Azure Tables input binding

When working with a single table entity, the Azure Tables input binding can bind to the following types:

Type Description
A JSON serializable type that implements ITableEntity Functions attempts to deserialize the entity into a plain-old CLR object (POCO) type. The type must implement ITableEntity or have a string RowKey property and a string PartitionKey property.
TableEntity1 The entity as a dictionary-like type.

When working with multiple entities from a query, the Azure Tables input binding can bind to the following types:

Type Description
IEnumerable<T> where T implements ITableEntity An enumeration of entities returned by the query. Each entry represents one entity. The type T must implement ITableEntity or have a string RowKey property and a string PartitionKey property.
TableClient1 A client connected to the table. This offers the most control for processing the table and can be used to write to it if the connection has sufficient permission.

1 To use these types, you need to reference Microsoft.Azure.Functions.Worker.Extensions.Tables 1.2.0 or later and the common dependencies for SDK type bindings.

Azure Tables output binding

When you want the function to write to a single entity, the Azure Tables output binding can bind to the following types:

Type Description
A JSON serializable type that implements [ITableEntity] Functions attempts to serialize a plain-old CLR object (POCO) type as the entity. The type must implement [ITableEntity] or have a string RowKey property and a string PartitionKey property.

When you want the function to write to multiple entities, the Azure Tables output binding can bind to the following types:

Type Description
T[] where T is one of the single entity types An array containing multiple entities. Each entry represents one entity.

For other output scenarios, create and use a TableClient with other types from Azure.Data.Tables directly. See Register Azure clients for an example of using dependency injection to create a client type from the Azure SDK.

Next steps