title: Entityframework with an existing database - navigation properties not working
body: <p>I have a set of Entities:</p>
  
  <pre><code>public class Board : EntityBase
  {
      public ICollection&lt;Slot&gt; Slots { get; set; }
  }
  
  public class Slot : EntityBase
  {        
      public ICollection&lt;Card&gt; Cards { get; set; }
  
      public string Header { get; set; }
  
      public int BoardId { get; set; }
  }
  
  public class Card : EntityBase
  {        
      public string Description { get; set; }
  
      public string Title { get; set; }
  
      public int SlotId { get; set; }
  }
  </code></pre>
  
  <p>And corresponding database tables:</p>
  
  <pre><code>CREATE TABLE Boards
  (
      Id INT PRIMARY KEY,
      UserId INT NOT NULL,
      CONSTRAINT FK_Users_UserId FOREIGN KEY (UserId)
      REFERENCES Users(Id)
  )
  
  CREATE TABLE Slots
  (
      Id INT PRIMARY KEY,
      Header NVARCHAR(MAX),
      BoardId INT NOT NULL,
      CONSTRAINT FK_Slots_BoardId FOREIGN KEY (BoardId)
      REFERENCES Boards(Id)
  )
  
  CREATE TABLE Cards
  (
      Id INT PRIMARY KEY,
      Title NVARCHAR(MAX),
      Description NVARCHAR(MAX),
      SlotId INT NOT NULL,
      CONSTRAINT FK_Cards_SlotId FOREIGN KEY (SlotId)
      REFERENCES Slots(Id)
  )
  </code></pre>
  
  <p>When attempting retrieving and instantiate a 'Board' from the database it's not populating the 'Slots' property. It seems that Entity framework is unable to recognise that there's a foreign key constraint. My understanding is that if the properties are not virtual they will be eager loaded, please correct me if i'm wrong.</p>
  
  <p>Is there something that I'm missing / need to setup to make navigation properties work?</p>
  
  <p>The calling code:</p>
  
  <pre><code>Context.Boards.Find(id);
  </code></pre>
  
  <p>My DbContext:</p>
  
  <pre><code>public class SampleContext : DbContext, IUnitOfWork
  {
      public SampleContext() : base("name=SampleApplication") { }
  
      public void Save()
      {
          SaveChanges();
      }
  
      public DbSet&lt;Board&gt; Boards { get; set; }
      public DbSet&lt;Card&gt; Cards { get; set; }
      public DbSet&lt;Slot&gt; Slots { get; set; }
  }
  </code></pre>
  
  <p><strong>I have made the navigation properties virtual and loaded as follows, this is now working:</strong></p>
  
  <pre><code>public Board GetBoard(int id)
  {            
      var board = Context.Boards.Find(id);
  
      Context.Entry(board)
          .Collection(b =&gt; b.Slots)
          .Load();
  
      return board;
  }
  </code></pre>