如何在.NET Core项目中使用WindowsAzure.Storage.Table?

时间:2017-07-11 17:40:09

标签: azure asp.net-core .net-core azure-storage

我在Visual Studio 2017中新创建的ASP.NET Core Web项目中安装了Windows Azure Storage 8.1.4 NuGet包。

实际上我尝试使用它,就像Microsoft docmentation建议(table.ExecuteQuery(query))一样,但只有#34; Async"方法:

enter image description here

代码:

public class HelloWorldController : Controller
{
    public string ReadTables() {
        CloudStorageAccount storage = CloudStorageAccount.Parse(connStr.MyTablesConnStr);
        CloudTableClient tableClient = storage.CreateCloudTableClient();
        CloudTable table = tableClient.GetTableReference("themes");

        StringBuilder response = new StringBuilder("Here is your test Table:");
        var query = new TableQuery<ProjectThemeEntity>() {
            SelectColumns = new List<string> {"RowKey", "Description" }
        };

        // No way to do it in the controller action ?! ----------
        var items=await table.ExecuteQuerySegmentedAsync<ProjectThemeEntity>(query, null);

        foreach (ProjectThemeEntity item in items) {
            response.AppendLine($"Key: {item.RowKey}; Value: {item.Description}");
        }

        return response.ToString();
    }

我发现过去有类似的问题,例如this one ...

知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

@Serge .NET Core尚未包含API的同步实现。所以你可以使用ExecuteQuerySegmentedAsync 。检查this

您关注的文章也没有说它适用于.NET Core。

enter image description here