代码之家  ›  专栏  ›  技术社区  ›  AlexB

如何在.NET Core 2.2应用程序中创建CloudTableClient?

  •  -1
  • AlexB  · 技术社区  · 6 年前

    我需要一件非常简单的事情-我需要在我的 应用程序使用 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 Core2.2的!

    我们不要混在一起 Microsoft.Azure.Storage公司 包装!

    0 回复  |  直到 6 年前
        1
  •  0
  •   AlexB    6 年前

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

        2
  •  0
  •   Aleksey    5 年前

    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();