目前,我正在使用 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/