我有以下数据
范畴
产品
项目
什么是查询,以便我得到多个列表,
ListOfCategory包含CategoryName和ListOfProduct<>
ListOfProduct包含ProductName和ListOfItems<>
ListOfItems<>包含ItemName和ItemID
var cats = (from g in CMP.tblCategories
join proc in CMP.tblProducts
on g.CategoryID equals proc.CategoryID
join item in CMP.tblItems
on proc.ProductID equals item.ProductID
select new { Cat = g.Name, Pro = proc.Name, Itm = item.Name, ItmID = item.ItemID });我知道这很不对,所以请帮帮我
发布于 2015-05-04 09:16:47
您可以使用Linq中的子查询简化您的需求。
//获取包含所有详细信息的项目列表
var Items = (from g in CMP.tblCategories
join proc in CMP.tblProducts
on g.CategoryID equals proc.CategoryID
join item in CMP.tblItems
on proc.ProductID equals item.ProductID
select new { Category = g.Name, ProductName = proc.Name, ItemName = item.Name, ItemID = item.ItemID });
//Group by ProductName to get a list of ProductName , List<Items>
var Products = (from i in Items
group i by i.CategoryName into g
select new { CategoryName = g.Key,
Products = (from p in Items
group p by p.ProductName into Productgroup
select new {ProductName = Productgroup.Key, Items = Productgroup})
}).ToList();https://stackoverflow.com/questions/30025991
复制相似问题