【问题标题】:How can I create a CloudTableClient in .NET Core 2.2 app?如何在 .NET Core 2.2 应用程序中创建 CloudTableClient?
【发布时间】:2019-03-09 10:56:20
【问题描述】:

这在 .NET Core 2 中已经有很长一段时间了!

我需要一个非常简单的东西 - 我需要在我的 .NET Core 2.2 应用程序中使用 Microsoft.Azure.CosmosDB.Table 包中的表存储。好的,让我们这样做,好吗?

首先,让我们创建CloudTableClient

using Microsoft.Azure.CosmosDB.Table;
using Microsoft.Azure.Storage.Common;

…

CloudTableClient tableClient = new CloudTableClient(
  new Uri("[WHAT TO PUT IN HERE in case of Azure and Emulator???]"),
  new Microsoft.Azure.Storage.Auth.StorageCredentials() // => **THIS DOES NOT EVEN COMPILE! Auth is not a part of the package **
);

不错!我们从这里去哪里? 请不要向我指出示例 - 它们不适用于 .NET Core 2.2!

我们不要混用 Microsoft.Azure.StorageMicrosoft.WindowsAzure.Storage 包!

这个问题什么时候解决?如何创建 CloudTableClient 并使用 CloudTable?

【问题讨论】:

  • 这是咆哮还是问题?
  • 对于 CloudTableClient 构造函数的第二个参数,documentation for StorageCredentials 似乎很合理。
  • 您是否尝试在 .NET Core 2.2 中混合使用 Microsoft.Azure.Storage 和 Microsoft.WindowsAzure.Storage 包???
  • 啊,所以它是一个不同的 StorageCredentials 类。好的。如果您可以编辑问题以使不同类型更清晰,以及您 尝试 构造 StorageCredentials 对象(以及您正在使用的确切 NuGet 包)的内容,您可能会发现人们是能更好地帮助你。虽然我可以理解想要发泄情绪,但只是咆哮并不是获得帮助的最佳方式。
  • 另外值得指出的是,Microsoft.Azure.Cosmos.Table 仍处于预览阶段,所以希望它有问题,不要在生产项目中使用它。恐怕你只需要耐心等待,也许继续Microsoft Azure Cosmos DB .NET SDK github打开一个新问题并在那里咆哮。

标签: c# azure .net-core azure-table-storage .net-core-2.2


【解决方案1】:

这很好用:

var tableName = "TestTempTable";
var storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=....;AccountKey=....;EndpointSuffix=core.windows.net";
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
var tableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());
var table = tableClient.GetTableReference(tableName);
await table.CreateIfNotExistsAsync();

【讨论】:

    【解决方案2】:

    我必须得出结论,在 .NET Core 2.x 项目中无法使用 Azure 表。降级到某些旧包或预览版本不是一种选择。

    【讨论】:

      猜你喜欢
      • 2020-03-08
      • 2019-07-28
      • 2018-09-29
      • 1970-01-01
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      • 2019-05-19
      • 2019-06-21
      相关资源
      最近更新 更多