title: Force inner join from EF Cores Include() on optional relationship
body: <p>We changed a relationship from required to optional, now the resulting SQL produced by EF Core's Include() does a left outer join rather than inner join. Problem is that those optional entities have query filters on them that is required.</p>
  
  <p>Let's say we have the following;</p>
  
  <pre><code>public class First 
  {
      public int? SecondId { get; set; }
  }
  public class Second 
  {
      public First First { get; set; }
      public int ThirdId { get; set; }
  }
  public class Third
  {
      public Second Second { get; set; }
      public string Tenant { get; set; }
  }
  
  public class MyContext : DbContext 
  {
      protected readonly string _tenant;
      ...
      modelBuilder.Entity&lt;Third&gt;(p =&gt;
      {
          p.HasQueryFilter(x =&gt; Tenant == _tenant);
      });
      ...
  }
  </code></pre>
  
  <p>And then we do the following:</p>
  
  <pre><code>MyContext.First.Include(p =&gt; p.Second).ThenInclude(p =&gt; p.Third);
  </code></pre>
  
  <p>This will produce a LEFT OUTER JOIN since the relationship is optional. This will of course then bypass the query filter. Is there a way to make this Include an INNER JOIN instead?</p>
  
  <p>Currently this is solved with adding some more conditions to the where later:</p>
  
  <pre><code>.Where(p =&gt; p.Second.Third.Tenant == _tenant);
  </code></pre>
  
  <p>But this is undesirable since in some edge cases the _tenant is null and will then give the wrong data. </p>
  
  <p>I know I can flip it around and go for</p>
  
  <pre><code>MyContext.Third.Include() ...
  </code></pre>
  
  <p>But this is also undesirable as First in this scenario has a lot of other related data and I don't want to endlessly chain Include().ThenInclude() to the point of ad absurdum.</p>
  
  <p>Can I force inner joins with optional entities? Or do I manually have to write the SQL for this?</p>