title: Entity Framework 5 - code first array navigation property one to many with Interface Type
body: <p>These are my classes:</p>
  
  <pre><code>public class Post : IPost
  {
      public int Id { get; set; }
      public virtual int[] DuplicateOf { get; set; }
      public virtual ICommentInfo[] Comments { get; set; }
  }
  
   public class CommentInfo : ICommentInfo
  {
      public virtual string Author { get; set; }
      public virtual int Id { get; set; }
      public virtual string Text { get; set; }
  
      public virtual int PostId{ get; set; }
      [ForeignKey("PostId")]
      public virtual Post Post { get; set; }
  }
  </code></pre>
  
  <p>With this CommentConfiguration added to OnModelCreate():</p>
  
  <pre><code>HasRequired(c =&gt; c.Post)
              .WithMany(b=&gt;(ICollection&lt;CommentInfo&gt;) b.Comments)
              .HasForeignKey(b=&gt;b.PostId)
              .WillCascadeOnDelete(true);
  </code></pre>
  
  <p>I really cannot understand why the property Comments is always null, and why EF doesn't initialize it since it's virtual. 
  I tried disabling lazy loading too, but when i try loading the navigation property with <code>context.Post.Include("Comments")</code> an error tells me that "There is not a navigation property called Comments".
  So I tried using Entity Framework Power Tools Beta 3 to see the Entity Data Model, and I discovered that there is not a navigation end for table "Post" even if there is the relationship between the two tables and there's the Comment table end too.</p>
  
  <p>I sincerly don't know which way to turn, could be a problem of Array?? Should I use an Icollection property??
  Though I cannot change the type of that property because Post is implementing an Interface.</p>
  
  <p>Every sample I look at is clear and easy to make work. Please help me.. Thank you in advance.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This is what I changed after looking at the <a href="http://antix.co.uk/Blog/EF4-Code-First-and-Interface-Property-Types" rel="nofollow">link</a> I posted yesterday.</p>
  
  <pre><code>  public class Post : IPost
    {
      public int Id { get; set; }
      public virtual int[] DuplicateOf { get; set; }
      public virtual ICollection&lt;CommentInfo&gt; Comments { get; set; } 
      ICommentInfo[] IPost.Comments { 
        get { return Comments ; } 
        set { Comments = (CommentInfo[])value; } }
    }
  </code></pre>
  
  <p>The exception is: <code>System.ObjectDisposedException :The ObjectContext instance has been disposed and can no longer be used for operations that require a connection</code> and raises when the application tries to get the Comments.
  If I remove the <code>virtual</code> key the exception disappear but the property remain always null and the values don't persist in any way.</p>
  
  <p><strong>EDITv2</strong>
  I've solved my problem adding a new property and map my old property to it.</p>
  
  <pre><code>public class Post : IPost
  {
      public int Id { get; set; }
      public virtual int[] DuplicateOf { get; set; }
      public ICommentInfo[] Comments
      {
          get { return ListComments.ToArray(); }
  
      }
      public List&lt;CommentInfo&gt; ListComments {get;set;}
  }
  </code></pre>
  
  <p>In my PostConfiguration  OnModelCreate() I used the ListComments property as a navigation property like this:</p>
  
  <pre><code>HasMany(b =&gt; b.ListComments)
                  .WithRequired(c=&gt;c.Post)
                  .HasForeignKey(c=&gt;c.PostId)
                  .WillCascadeOnDelete(true);
  </code></pre>
  
  <p>Now it perfectly works, it was simpler than I expected and when I try to receive the Comments Collection, if I include the "ListComments" property, I get the array of  Post.
  Thank you for your help!</p>