title: Entity Framework Code First existing database mapping relationship
body: <p>I have an existing database which I would like to use Entity Framework Code First against in the most simple way possible. It is only a small database.</p>
  
  <p>I have created simple POCO classes which mirror the database tables:</p>
  
  <p>e.g.</p>
  
  <p><a href="https://i.stack.imgur.com/kZeSu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kZeSu.png" alt="enter image description here"></a></p>
  
  <pre><code>public class Author
  {
      [Key]
      public int AuthorID { get; set; }
      public string AuthorName { get; set; }
      public virtual ICollection&lt;Books&gt; Books { get; set; }
  }
  
  public class Books
  {
      [Key]
      public int BookID { get; set; }
      public string BookName { get; set; }
      public int AuthorID { get; set; }
  
  }
  </code></pre>
  
  <p>And a DbContext as follows:</p>
  
  <pre><code>public class Entities : DbContext
  {
      public Entities(string connString)
      : base(connString)
  {
  }
      public DbSet&lt;Author&gt; Authors { get; set; }
      public DbSet&lt;Books&gt; Books { get; set; }
  </code></pre>
  
  <p>When I run my application, and select the first Author from my database, the AuthorID and AuthorName properties are populated correctly. However, the collection of Books is not populated. Instead there is an exception of type 'System.Data.EntityCommandExecutionException', and an inner exception of: 'Invalid column name 'Author_AuthorID'.</p>
  
  <p>How can I establish correctly the link between Author and Books? (i.e. one to many, one Author can have many Books). I have created the Code First very simply - no migrations or auto-generation in any way, and would like to keep it as simple as this.</p>
  
  <p>Many thanks for any help,
  Martin</p>