title: MVC c# Comments Listing / Display
body: <p>I am trying to find the most efficient way to display a set of nested comments from a database schema and into a c# object that i can convert to a serialised JSON object.</p>
  
  <p>My Schema is as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/lRpl5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lRpl5.jpg" alt="ScreenShot Schema"></a></p>
  
  <p>As you can see from the screenshot there is an Update which has a parent issue id (not relevant here) and a Comment.  There is also a ParentUpdateID which enables the table to store nested replies for each reply and so on.</p>
  
  <p>I have created a class within c# which i want to convert the results from my Entity Framework call;</p>
  
  <pre><code>    /// &lt;summary&gt;
  /// The resource view model.
  /// &lt;/summary&gt;
  public class Comment
  {
      /// &lt;summary&gt;
      /// Gets or sets the id.
      /// &lt;/summary&gt;
      public Guid Id { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the body.
      /// &lt;/summary&gt;
      public string Body { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the modified by.
      /// &lt;/summary&gt;
      public string ModifiedBy { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the modified date.
      /// &lt;/summary&gt;
      public DateTime ModifiedDate { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the created by.
      /// &lt;/summary&gt;
      public string CreatedBy { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the created date.
      /// &lt;/summary&gt;
      public DateTime CreatedDate { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the parent comment id.
      /// &lt;/summary&gt;
      public Guid? ParentCommentId { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the children.
      /// &lt;/summary&gt;
      public List&lt;Comment&gt; Children { get; set; }
  }
  </code></pre>
  
  <p>And here is how i am retrieving the List of Comments / Updates from the database.</p>
  
  <pre><code>List&lt;ClientIssuesUpdate&gt; updates = this.db.ClientIssuesUpdates.Where(i =&gt; i.IssueId == issueId).ToList();
  </code></pre>
  
  <p>Is there a clever way through either a loop or using lync that can order all of the comments showing most recent first, but then display in date order each comments children and so on. (e.g. All comments without a ParentUpdateId would be to level comments)</p>
  
  <p>Any guidance would be helpful so i can learn for the future.</p>
  
  <p>Many thanks</p>