title: EF Lazy Loading, extraction of query to another method results in null for navigation property
body: <p>I am using Entity Framework and have a model that Access Control Listings are applied to. I have a One-To-Many relationship between my Model and the ACL Model.</p>
  
  <p>In a majority of place that I need to query my model, I only need to return the models which have a corresponding ACL.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>var myUnits = _context.Units
      .Include(unit =&gt; unit.AccessControlRules)
      .Where(unit =&gt; unit.AccessControlRules.FirstOrDefault(acl =&gt; acl.UserId == 15) != null);
  </code></pre>
  
  <p>This works correctly every time. It will only return units that have an acl for the user with Id 15.</p>
  
  <p>However, when I extract this into the following form, it throws a value cannot be null exception because unit.AccessControlRules is null.</p>
  
  <pre><code>    var myUnits = _context.Units
      .Include(unit =&gt; unit.AccessControlRules)
      .Where(unit =&gt; permissionCheck(unit));
  
      private bool permissionCheck(Unit unit)
      {
          return unit.AccessControlRules.FirstOrDefault(acl =&gt; acl.UserId == 15) != null;
      }
  </code></pre>
  
  <p>It's the exact same code, whereas the second (non-working) version <code>unit.AccessControlRules == null</code>.</p>
  
  <p>Could someone explain this behavior?</p>