【发布时间】:2021-08-04 15:19:51
【问题描述】:
此代码的性能符合预期。
var soldQtyForEachItem = await _context.InvoiceProduct
.Where(x => x.ProductId != 0)
.GroupBy(x => x.ProductId)
.Select(grp => new CompanyProducts
{
CompanyProductId = grp.Key,
CompanyProductSoldQuantity = grp.Sum(item => item.QuantitySold)
}).ToListAsync();
问题:
我现在需要加入另一个名为 Products 的表,并按 Id 过滤 InvoiceProduct 表并检索 ProductsItemName 是 Products 表中的一行;那么都需要转到下面的自定义类型“CompanyProducts”。
请问我该如何实现呢?
public class CompanyProducts
{
public int CompanyProductId { get; set; }
public int CompanyProductName { get; set; }
public int CompanyProductSoldQuantity { get; set; }
}
InvoiceProduct 表是多对多的,这意味着一个 InvoiceId 可能有多个 ProductId。
Products 表具有 ProductId、ProductsItemName 等属性。
【问题讨论】:
-
嗨,伙计,你忘了问问题。你到底遇到了什么困难?
-
@MongZhu 谢谢你帮助我。我刚刚编辑了帖子以清楚地显示问题。