.net - 有没有办法从表中获取不同的 PartionKeys

标签 .net azure azure-table-storage

目前,我正在使用 PartitionKey 来区分将数据存储到 Azure 表服务中的设备。我想构建一个允许我浏览该数据的查看器,但如果能够对其进行结构化,以便我可以“按设备”或按 PartitionKey 查看数据,那就太好了。查看器应用程序不会知道存在哪些设备,因此如果我能够以某种方式获取给定表中不同 PartionKey 的列表,那就太好了。这是可能的,还是我将被降级为创建一个元数据表,在其中为每个设备插入一个新行,然后使用它进行查询?

最佳答案

创建一个表来存储您的分区。按您使用的表名称对表进行分区,并为您创建的每个分区添加一个条目。

public class PartitionEntry : TableServiceEntity { }

tableServiceContext.AddObject("TablePartitions", new PartitionEntry
{
    PartitionKey = "<table name>",
    RowKey = "<partition key>",
});
tableServiceContext.BeginSaveChanges(SaveChangesOptions.ContinueOnError, null, null);

然后只需查询该表即可获取分区列表。这对我来说非常容易管理。

var tbl = tableServiceContext.CreateQuery<PartitionEntry>("TablePartitions");
return tbl.Where(i => i.PartitionKey == "<table name>")
          .Select(i => new { PartitionKey = i.RowKey, });

我打赌这可以优化。

关于.net - 有没有办法从表中获取不同的 PartionKeys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12862520/

相关文章:

c# - 您如何满足 WebApi 查询字符串中的 AND 和 OR 搜索?

c# - 使用 WebBrowser 显示对话框

python - 如何修复云azure函数中的 "No module named ' azure.storage'“错误?

javascript - 每日随机报价生成器

azure - 如何链接 Azure 数据工厂管道

java - 如何让 Java 作业只确定一次日期

c# - 如何将 Canvas 绑定(bind)到矩形列表

azure - 当 UseDevelopmentStorage=true 时,本地机器上的 Azure 跟踪日志在哪里

azure - 访问 Azure 表存储表时使用字符串名称

azure - 使用 REST API 监控 Azure 存储