1
我正在使用.NET MVC4和實體框架開發一個新項目。我有一個產品表,我試圖用分組來選擇產品。無法使用LINQ填充表格的分組列表
我的模型:
public class Cart
{
public long Index { get; set; }
public List<Products> ProductList = new List<Products>();
public int ItemCount { get; set; }
public decimal Total { get; set; }
}
我的查詢:
var result = from p in productList
group p by p.id into grp
select new
{
Index = grp.Key,
ProductList = grp.ToList<Products>(),
ItemCount = grp.Count(),
Total = grp.Sum(w => w.price)
};
然後,我想申請結果車的名單。但我在某個時候失敗了。請你能幫我做到這一點。