title: entity framework one to many relation but Object reference not set to an instance of an object
body: <p>I am beginner, I have 3 entities: member, post, comment. A member has many posts, and a post has many comments.</p>
  
  <pre><code>   public class Member
     {
              [Key]
              public int Id{get;set;}    
              public string Name{get;set;}   
              public virtual ICollection&lt;Post&gt; Posts { get; set; }    
     }
     public class Post
     {            
         [Key]
         public int PostId{get;set;}        
         public string Subject{get;set;}        
         public int AccountId{get;set;}             
         public virtual Member member{get;set;}        
         public ICollection&lt;Comment&gt; Comments { get; set; }
     }
  
     public class Comment
     {
        [Key]
         public int CommentId{get;set;}    
         public string Body{get;set;}
         public int PostId { get; set; }
         public virtual Post post { get; set; }
     }
  </code></pre>
  
  <p>And this is relationship defined in my context:</p>
  
  <pre><code>           modelBuilder.Entity&lt;Post&gt;()
                  .HasRequired(c=&gt;c.member)
                  .WithMany(t=&gt;t.Posts)
                  .HasForeignKey(d=&gt;d.AccountId);
  
             modelBuilder.Entity&lt;Comment&gt;()
                 .HasRequired(c =&gt; c.post)
                 .WithMany(t =&gt; t.Comments);
                 .HasForeignKey(d=&gt;d.AccountId);
  </code></pre>
  
  <p>I use asp.net mvc. tables and relations are OK, but in Post controller in Details view:</p>
  
  <pre><code> @model sishan.Models.Friend
    .
    .
    .  
  
   @foreach (var item in Model.Comments)
     {
        &lt;p&gt; @item.Body&lt;/p&gt;
     }
  </code></pre>
  
  <p>I Get this error: 
  Object reference not set to an instance of an object.</p>
  
  <p>I have not any syntax error.</p>
  
  <p>Please help me.
  Sorry for my English.</p>