Azure 表存储:使用现有属性作为 PartitionKey 和 RowKey
我有一个模型,其中现有字段已经非常适合 RowKey 和 PartitionKey,但我不知道如何分配它们并且不包含重复数据。考虑这个例子:
public class ClassA : ITableEntity
{
// My existing fields
public string Id { get; set; }
public string Receiver { get; set; }
public DateTimeOffset? Received { get; set; }
// ITableEntity fields
public string PartitionKey { get => Receiver; set => Receiver = value; }
public string RowKey { get => Id; set => Id = value; }
public DateTimeOffset? Timestamp { get => Received; set => Received = value; }
public ETag ETag { get; set; }
}
这可行,但我们按预期得到了重复的数据。然后我尝试将 [IgnoreDataMember] 添加到 Id、Receiver 和 Received,但无法使用 TableClient.QueryAsync(x => x.Id == "...") 进行查询。
有没有办法可以将 ITableEntity 映射到现有字段,以便我:
- 避免重复数据
- 可以使用现有字段进行查询
我正在使用 Azure.Data.Tables 版本 12.4.0
I have a model where existing fields already fits quite nicely for RowKey and PartitionKey but I don't know how to assign them and not have duplicate data. Consider this example:
public class ClassA : ITableEntity
{
// My existing fields
public string Id { get; set; }
public string Receiver { get; set; }
public DateTimeOffset? Received { get; set; }
// ITableEntity fields
public string PartitionKey { get => Receiver; set => Receiver = value; }
public string RowKey { get => Id; set => Id = value; }
public DateTimeOffset? Timestamp { get => Received; set => Received = value; }
public ETag ETag { get; set; }
}
This works but we get duplicate data as expected. Then I tried to add [IgnoreDataMember] to Id, Receiver and Received but then I cannot query using TableClient.QueryAsync(x => x.Id == "...").
Is there a way I can map the ITableEntity to my exisiting fields so I:
- Avoid having duplicate data
- Can query using my exisiting fields
I'm using Azure.Data.Tables Version 12.4.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于表存储,无法将任何属性指定为 PartitionKey 和 RowKey 属性。这些属性必须命名为 PartitionKey 和 RowKey。
您可以查询任何现有字段,但该查询不会被视为与 PartitionKey/RowKey 字段查询相同的处理方式,并且将导致全表扫描。
With Table Storage, it is not possible to designate any attributes as PartitionKey and RowKey attribute. The attributes must be named PartitionKey and RowKey.
You can query on any existing fields but the query will not be treated the same as querying on PartitionKey/RowKey fields and will result in full table scan.