我对Azure表存储非常陌生,而且分区键的概念仍然是我不知道我是否正确进行的一个领域。以下是我提出的存储博客评论数据的解决方案。我已经评论了所有内容,所以我希望我的思想能够根据代码自我解释。
感谢我可能没有考虑过的任何想法......
-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; }
}
答案 0 :(得分:1)
我觉得你的设计很好看。这取决于你将如何检索它们。在您的示例中,您有一个博客系统,所以我假设您需要单独检索您的博客及其所有评论(以及子评论),然后您可以将博客ID作为分区键并在一个查询中检索所有评论还要确保同一博客下的所有评论都存储在azure数据中心的同一数据集群中,并具有最高性能。
如果您需要更高的性能,我建议您同时存储作者姓名,以减少应用层中的联接操作。