Question

I'm very new to Azure table storage, and the concept of a partition key is still an area where I'm not yet confident to know if I'm proceeding correctly. Below is my proposed solution for storing blog post comment data. I've commented everything so I hope my thought is self explanatory based on the code.

  • Do the row and partition key look ok?
  • Do I actually need a field called "CommentId?" (In the example I saw, there seemed to be no specific ID field as one would have in a traditional SQL store.
  • What should the scope of a table be? (I currently envision one table for all comments across all blog posts.)

Thanks for any thoughts I may not have considered...

-Ben

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; }
}
Was it helpful?

Solution

Your design looks fine I think. It depends on how you are going to retrieve them. In your example you have a blog system so I assumed you need to retrieve your blog alone with all its comments (and sub-comments as well), then you could have blog id as the partition key and retrieve all comments in one query and it also ensure all comments under the same blog are stored in the same data cluster in azure data center with max performance.

If you need more performance I'd like suggest you to store author name as well, to reduce the join operation in your application layer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top