title: EF Core Lambda Expression Object Reference not set to an instance of an object on multiple joins
body: <p>I am having weird error of <code>NullReferenceException</code> while querying the data using Entity framework core lambda syntax.</p>
  
  <p>using this code</p>
  
  <pre><code>           var usersWithRights = await _dbContext.TblUsers.Where(x =&gt; x.IsInternal).Select(x =&gt; new
              {
                  RightIds = x.TblInternalUserRoles.FirstOrDefault().Role.TblInternalRoleRights.Select(i =&gt; i.RightId).ToList()
              }).ToListAsync();
  </code></pre>
  
  <p>Where as the same code works when I apply <code>Count</code> instead of <code>Select</code> like</p>
  
  <pre><code>           var usersWithRights = await _dbContext.TblUsers.Where(x =&gt; x.IsInternal).Select(x =&gt; new
              {
                  RightIds = x.TblInternalUserRoles.FirstOrDefault().Role.TblInternalRoleRights.Count
              }).ToListAsync();
  </code></pre>
  
  <p>Above code using <code>Count</code> give me the accurate result of count but I want to select the <code>RightIds</code>. I have crossed check that the record exists in my database and as a result when I query using <code>Count</code> it gives me the accurate result.</p>
  
  <p>I just want to ask if there is any limit on Entity framework core while joining data? like are there a maximum number of joins allowed in EF Core or I can join any number of tables?</p>