title: Entity Framework LINQ Multiple Column Count(Distinct)
body: <p>I'm not entirely sure how to translate the following SQL into LINQ Fluent API.  Any help would be great</p>
  
  <pre><code>select count(distinct thread.Id) as ThreadCount, count(distinct segment.Id) as SegmentCount
  from Segment 
  inner join SegmentCommunicator as SegmentCommunicator
      on Segment.Id = SegmentCommunicator.SegmentId
  inner join Thread
      on Thread.Id = Segment.ThreadId
  where SegmentCommunicator.CommunicatorId in (94, 3540, 6226, 10767, 20945)
  </code></pre>
  
  <p>Currently, I know how to do this in 2 queries but for the life of me I can't figure out how to condense down into one.  Any help would be much appreciated </p>
  
  <pre><code>        var aggregate1 = _threadProvider
                  .AsQueryable()
                  .SelectMany(t =&gt; t.Segments)
                  .Where(s =&gt; s.SegmentCommunicators.Any(sc =&gt; communicatorIds.Contains(sc.CommunicatorId)))
                  .Select(s =&gt; s.ThreadId)
                  .Distinct()
                  .Count();
  
          var aggregate2 = _threadProvider
              .AsQueryable()
              .SelectMany(t =&gt; t.Segments)
              .Where(s =&gt; s.SegmentCommunicators.Any(sc =&gt; communicatorIds.Contains(sc.CommunicatorId)))
              .Select(s =&gt; s.Id)
              .Distinct()
              .Count();
  </code></pre>