我的系统有表PRODUC和FAULTS。每个产品都可能有多个故障(故障表有一个外键ProductID)。我需要获得一个大约十个产品的列表,其中包含最多的故障。我尝试了以下但它似乎不起作用(我需要的字段是产品名称,价格,ID和故障数量):
return (from p in Entity.Products
join f in Entity.Faults
on p.ProductID equals f.ProductID
group f by new { f.ProductID, p.Name, p.Price } into product
select new CountFaultView()
{
ProductID = product.Key.ProductID,
Name = product.Key.Name,
Price = product.Key.Price,
FaultsCount = product.Key.Name.Count()
}
).OrderByDescending(x => x.FaultsCount).Take(10);
}
我正在尝试计算显示名称的次数,但显然我似乎遇到了错误; o