Azure表存储:为注释数据配置分区和行键的最佳方法?

Azure表存储:为注释数据配置分区和行键的最佳方法?,azure,nosql,azure-table-storage,data-partitioning,Azure,Nosql,Azure Table Storage,Data Partitioning,我对Azure表存储非常陌生,分区键的概念仍然是一个我还不确定是否正确进行的领域。下面是我建议的存储博客帖子评论数据的解决方案。我已经注释了所有内容,所以我希望我的想法是基于代码的自我解释 行和分区键看起来正常吗 我真的需要一个名为“CommentId”的字段吗?(在我看到的示例中,似乎没有像传统SQL存储中那样的特定ID字段 一个表的范围应该是什么?(我目前设想一个表,用于所有博客帖子的所有评论。) 谢谢你给我一些我可能没有考虑过的想法 -本 公共类CommentEntity:TableE

我对Azure表存储非常陌生,分区键的概念仍然是一个我还不确定是否正确进行的领域。下面是我建议的存储博客帖子评论数据的解决方案。我已经注释了所有内容,所以我希望我的想法是基于代码的自我解释

  • 行和分区键看起来正常吗
  • 我真的需要一个名为“CommentId”的字段吗?(在我看到的示例中,似乎没有像传统SQL存储中那样的特定ID字段
  • 一个表的范围应该是什么?(我目前设想一个表,用于所有博客帖子的所有评论。)
谢谢你给我一些我可能没有考虑过的想法

-本

公共类CommentEntity:TableEntity
{
/// 
/// 
/// 
///注释的唯一标识符
///表示此注释引用的帖子的标识符
公共CommentEntity(int CommentId、int ReferencedBlogPostId)
{
this.PartitionKey=ReferencedBlogPostId.ToString();
this.RowKey=CommentId.ToString();
}
公共CommentEntity(){}
//public int CommentId{get;set;}(移到构造函数上方)
//public int ReferencedBlogPostId{get;set;}(移动到构造函数)
//如果这是对另一条评论的回复,请在此处引用该评论ID
public int ParentCommentId{get;set;}
//这篇文章发表的时间
公共日期时间PostedTime{get;set;}
//表示另一个数据存储中注释作者的Id值
公共int AuthorId{get;set;}
}

我认为您的设计看起来不错。这取决于您将如何检索它们。在您的示例中,您有一个博客系统,因此我假设您需要单独检索您的博客及其所有评论(以及子评论),然后您可以将blog id作为分区键,并在一个查询中检索所有评论,还可以确保同一blog下的所有评论以最高性能存储在azure数据中心的同一数据集群中


如果您需要更高的性能,我建议您也存储作者姓名,以减少应用程序层中的加入操作。

谢谢Shaun。您能为我澄清一下,我是否有责任在创建评论对象时创建CommentId?
public class CommentEntity : TableEntity
{

    /// <summary>
    /// 
    /// </summary>
    /// <param name="CommentId">Unique identifier for the comment</param>
    /// <param name="ReferencedBlogPostId">Identifier representing the post which this comment references</param>
    public CommentEntity(int CommentId, int ReferencedBlogPostId)
    {
        this.PartitionKey = ReferencedBlogPostId.ToString();
        this.RowKey = CommentId.ToString();
    }

    public CommentEntity() { }

   // public int CommentId { get; set; } (Moved to above constructor)
    // public int ReferencedBlogPostId { get; set; } (Moved to constructor)

    //If this is in reply to another comment, reference that CommentId here
    public int ParentCommentId { get; set; }

    //Time that the post was made
    public DateTime PostedTime { get; set; }

    //An Id value representing the author of the comment in another datastore
    public int AuthorId { get; set; }
}