我对 LINQ 非常陌生,并且在对表格进行分组时遇到了很大的麻烦,因此所有内容都加在一起。我试图让这个显示所有购买超过 50 美元的客户,即使他们有多次购买。在 SQL 数据库中使用 linq。这是我到目前为止所拥有的,请帮助。
public class TopCustomerVM
{
public string Name { get; set; }
public decimal DollarsSold { get; set; }
public static List<TopCustomerVM> GetResults()
{
ACEEntities db = new ACEEntities();
return (from c in db.Customers
join o in db.Orders on c.CustomerId equals o.CustomerId
join l in db.OrderLines on o.OrderId equals l.OrderId
into x
select new TopCustomerVM {
Name = c.FirstName + c.LastName,
DollarsSold = x.Sum(asdf => asdf.UnitCost * asdf.Quantity)
})
.OrderByDescending(lkj => lkj.DollarsSold)
.Where(lkj => lkj.DollarsSold > 50)
.ToList();
}
}