Derzeit jede Art von Unterscheidung innerhalb von Gruppen (wie Distinct innerhalb von ElementSelector von GroupBy oder ein anderes GroupBy innerhalb von ElementSelector von GroupBy ) wird von EF Core nicht unterstützt . Wenn Sie darauf bestehen, EF zu verwenden in diesem Fall müssen Sie einige Daten aus dem Speicher holen:
var result = (await _context.Items
.Select(p => new { p.ParentAId, p.ParentBId })
.Distinct()
.ToListAsync()) // When EF supports mentioned cases above, you can remove this line!
.GroupBy(i => i.ParentBId, i => i.ParentAId)
.ToDictionary(g => g.Key, g => g.Distinct().Count());