title: Navigation Property not loading when only the ID of the related object is populated
body: <p>I am trying to establish a many-to-one relationship. The entity that represents the “many” has a navigation property pointing back to the parent entity. It looks like this:</p>
  
  <pre><code>public abstract class BaseEntity
  {
  
      /// &lt;summary&gt;
      /// Key Field for all entities
      /// &lt;/summary&gt;
      /// 
      [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Guid Id { get; set; }
  
  
      /// &lt;summary&gt;
      /// Date entity was created
      /// &lt;/summary&gt;
      public DateTime DateCreated { get; set; }
  
      /// &lt;summary&gt;
      /// Last date Modified
      /// &lt;/summary&gt;
      public DateTime DateModified { get; set; }
  
      /// &lt;summary&gt;
      /// keep track of Row Version used for concurrency
      /// &lt;/summary&gt;
      [Timestamp]
      public Byte[] RowVersion { get; set; }
  
  }
  
  public abstract class Document : BaseEntity
  {
      #region Primitive Properties   
  
  
      /// &lt;summary&gt;
      /// Boolean value to determine if Document is in an active state
      /// &lt;/summary&gt;
      public bool IsActive { get; set; }
  
      /// &lt;summary&gt;
      /// Document comments and information
      /// &lt;/summary&gt;
      [Required]
      public string Description { get; set; }
  
      #endregion
  
      #region Navigation Properties
  
      public ICollection&lt;Comment&gt; Comments { get; set; }
  
      /// &lt;summary&gt;
      /// FK back to User who owns document
      /// &lt;/summary&gt;
      //public Guid OwnerId { get; set; }
  
      public Guid OwnerId { get; set; }
      /// &lt;summary&gt;
      /// Navigation Back to User who owns document
      /// &lt;/summary&gt;
      public User Owner { get; set; }
  
      #endregion
  }
  
  public class Project : BaseEntity
  {
      public string Name { get; set; }
      public string ProjectNumber { get; set; }
      public string Description { get; set; }
  
      public string CreatedBy { get; set; }
      public string ModifiedBy { get; set; }
      public string Currency { get; set; }
  
      #region Navigation Properties
  
      public virtual Address Address { get; set; }
      public virtual CompanyCode CompanyCode { get; set; }
      public virtual ICollection&lt;Contact&gt; TeamMembers { get; set; }
  
      #endregion
  }    
  
   public class Rfi : Document
   {
      public string Number { get; set; }
  
      #region Navigation Properties
  
      //This points back to a Project Entity
      public virtual Guid ProjectId { get; set; }
      public virtual Project Project { get; set; }
  
      #endregion
  }
  </code></pre>
  
  <p>So, when I insert the above entity, I am passing the ProjectId from the application into the Rfi entity (not the entire Project entity). Everything saves fine. The issue I am having is, when I pull the Rfi object back out of the database, the ProjectId is being populated, but the Project entity is null. I am using Lazy Loading, by default. Do I need to specify a navigation property on the Project entity, too? I don’t really want to. Unless, I can perform a mapping on my Rfi to accomplish this.</p>
  
  <p>Update:
  I assumed EF 4.1 would load my objects for me, but it seems, sometimes I need to explicitly include what objects I want to load. I am not entirely sure why. I am using a repository to query my entities. Here is the method I used to query the Rfi object:</p>
  
  <pre><code>    public IQueryable&lt;TEntity&gt; GetQuery(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate)
      {
         return _context.Set&lt;TEntity&gt;().AsQueryable();
      }
  </code></pre>
  
  <p>What I ended up doing, in my Service layer I call it like this:</p>
  
  <pre><code>public Rfi FindByNumber(string number)
  {
       var rfi = rfiRepository.GetQuery(r =&gt; r.Number == number).Include(r =&gt; r.Project).Single;
       return rfi
  }
  </code></pre>