現在、グループ内のあらゆる種類の区別(Distinctなど) ElementSelector内 GroupByの または別のGroupBy ElementSelector内 GroupByの )はEF Coreではサポートされていません 。 EFの使用を主張する場合 この場合、メモリ内のデータをフェッチする必要があります:
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());