Entity Framework-LINQ Mehrere Spalte Count(Distinct)

Ich bin mir nicht ganz sicher, wie übersetzt man den folgenden SQL in LINQ, Fluent-API. Jede Hilfe wäre toll,

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)

Derzeit, ich weiß, wie dies in 2 Abfragen, aber für das Leben von mir ich kann nicht herausfinden, wie zu kondensieren, down in einem. Jede Hilfe wäre sehr geschätzt werden

        var aggregate1 = _threadProvider
                .AsQueryable()
                .SelectMany(t => t.Segments)
                .Where(s => s.SegmentCommunicators.Any(sc => communicatorIds.Contains(sc.CommunicatorId)))
                .Select(s => s.ThreadId)
                .Distinct()
                .Count();

        var aggregate2 = _threadProvider
            .AsQueryable()
            .SelectMany(t => t.Segments)
            .Where(s => s.SegmentCommunicators.Any(sc => communicatorIds.Contains(sc.CommunicatorId)))
            .Select(s => s.Id)
            .Distinct()
            .Count();
  • Dank Ocelot20, Aber das erzeugt eine Liste der zählt. Ich will ein Ergebnis des 2 zählt die Basis der verschiedenen threadId count und distinct segmentId
InformationsquelleAutor Jon Gear | 2015-01-08
Schreibe einen Kommentar