title: EF Core 3, optimize lots of Include/ThenInclude
body: <p>I have a query like this</p>
  
  <pre><code>return await _ctx.Activities
              .Include(a =&gt; a.Attributes)
              .Include(a =&gt; a.Roles)
              .Include(a =&gt; a.Bookmarks)
              .Include(a =&gt; a.VideoMetas)
                  .ThenInclude(vm =&gt; vm.Instances)
              .Include(a =&gt; a.ImageMetas)
                  .ThenInclude(im =&gt; im.Instances)
              .Include(a =&gt; a.Procedure)
                  .ThenInclude(p =&gt; p.Attributes)
              .FirstOrDefaultAsync(a =&gt; a.Id == id);
  </code></pre>
  
  <p>Which turns out to be very slow. In <code>EF 6</code> you can do <code>.Include(v =&gt; v.VideoMetas.Select(vm =&gt; vm.Instances)</code> which is a bit faster (I guess, haven't looked at SQL Profiler and actual query tbh). How can I optimize that? I can also use <code>EF Plus</code> where it has <code>.IncludeOptimized()</code> but there is no version for <code>.ThenInclude()</code>. I heard I can use <code>.Select</code> instead of <code>.Include()</code> but really not sure how I can handle that in this query. </p>