如何使用 C# 连接到 Azure 存储 Table

How to connect to Azure Storage Table with C#

我想连接到现有的 Azure 存储 Table 并从中读取(过滤)数据。 我找到了一些示例,但每个人都使用过时的 WindowsAzure.Storage 命名空间。我无法从当前的 Microsoft 命名空间中找到 Azure.Storage.Common 或其他一些解决方案。 Azure.Storage.Blobs 有很多示例,但我需要 Table 存储服务的解决方案。非常感谢...

Azure.Data.Tables package is the current generation update to the Tables client library and is currently in beta. Samples can be found in the Azure SDK repository in the Tables sample地区。

另一个建议的解决方案是使用 Microsoft.Azure.Cosmos.Table 包。如描述中所述:

When used with Azure Table Storage service, this library offers similar APIs and functionalities as WindowsAzure.Storage 8.7.0.

可以找到它的完整文档 here

帮助您连接到 table 并执行以下操作的代码示例:

 private async Task<CloudTable> GetTable() {
        var storageAccount = CloudStorageAccount.Parse(StorageConnectionString);
        var tableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());
        var table = tableClient.GetTableReference(TableName);
        await table.CreateIfNotExistsAsync();
        return table;
    }