Здравствуйте, я уже получил ответ.
var topseller = await Context.Entities.Products
.GroupJoin(Context.Entities.AHPPartners,
products => products.AHPPartnerId,
ahp => ahp.Id,
(products, ahp) => ahp.Select(s => new { p = products, a = s }).DefaultIfEmpty(new { p = products, a = (AHPPartner)null })
).SelectMany(g => g)
.Join(Context.Entities.OrderProducts,
firstJoin => firstJoin.p.Id,
orderProducts => orderProducts.ProductId,
(firstJoin, orderProducts) => new { firstJoin.p, firstJoin.a, orderProducts }
)
.Select(s => new {
ProductName = s.p.Name,
ProductId = s.p.Id,
PartnerName = s.a.Name,
PartnerId = s.a.Id
})
.GroupBy(g => new { g.PartnerName, g.ProductName, g.ProductId, g.PartnerId })
.Select(s => new TopSellerProductDTO {
ProductName = s.Key.ProductName,
PartnerName = s.Key.PartnerName,
PartnerId = s.Key.PartnerId,
ProductId = s.Key.ProductId,
TotalCount = s.LongCount()
})
.ToListAsync();