其他相關表格請幫我完成以下查詢:LINQ GROUP BY查詢的幫助:選擇鍵
var results = from species in db.Species
join cats in db.Categories on species.CategoryId equals cats.CategoryId
join groups in db.Groups on cats.GroupId equals groups.GroupId
group groups by groups into g
select new GroupWithCategoryChildren
{
Group = g.Key,
Categories = (cats from above query for this same g.Key group)???
};
我可以用SQL做到這一點真的很容易,但我與LINQ掙扎。我想結束每個Group
的列表,並在上面的/主要單個查詢中加入cats
,理想情況下不需要在單獨的查詢中重新查詢該數據。
非常感謝
你能後你會怎麼做,在SQL?這將告訴我們你需要什麼,而LINQ專家可以很容易地爲你翻譯。 –
您可以在LINQ中使用子查詢,但正如香農所提到的,沒有看到您的SQL或所有這些表應該如何相互關聯,都無法回答您的問題。 – Connor
對不起,我意識到我沒有提供原始問題中的最佳解釋。 – Aaron