2014-03-14 24 views
0

我對Azure表存儲非常陌生,分區鍵的概念仍然是一個我還沒有信心知道我是否正確進行的區域。以下是我提出的用於存儲博客文章評論數據的解決方案。我已經評論過所有的東西,所以我希望我的想法是基於代碼的自我解釋。Azure表存儲:爲備註數據配置分區和行鍵的最佳方法?

  • 行和分區鍵看起來好嗎?
  • 我真的需要一個名爲「CommentId?」的字段嗎? (在我看到的例子中,似乎沒有具體的ID字段,就像傳統SQL存儲中的字段一樣。
  • 表的範圍應該是什麼?(我目前設想所有博客文章中的所有評論都有一張表。)

感謝我可能沒有考慮任何的想法...

-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; } 
} 

回答

1

你的設計看起來不錯,我認爲,這取決於你將如何對它們進行檢索在你的例子中你有一個博客系統我認爲你需要單獨檢索你的博客及其所有評論(以及子評論),然後你可以將博客ID作爲分區鍵並檢索一個查詢中的所有評論,並確保同一博客下的所有評論都是存儲在具有最高性能的天青數據中心的同一數據集羣中。

如果你需要更多的性能,我想建議你存儲作者的名字,以減少你的應用程序層的連接操作。

+0

謝謝肖恩。你能否爲我澄清一下,我是否有責任在創建Comment對象時創建CommentId? – BenjiFB

+0

我這麼認爲,BenjiFB –