我知道這可能在C#中已經回答了十幾次,但我在VB.Net中找到一個簡單的解決方案時遇到了困難(其他人都在使用多個連接組和所有這些其他垃圾我不需要,不能有效地過濾出我的解決方案)。LINQ:在VB.net中加入,分組,聚合在一起
本質上講,我試圖寫下面的(簡單)的SQL查詢到LINQ上VB.Net:
Select a.ID, a.First_Name, a.Last_Name, [Count] = count(b.ID), Last_Payment = max(b.Payment_Date)
from Members a
join Payments b on a.ID = b.Member_ID
group by a.ID, a.First_Name, a.Last_Name
我試過和走到這一步,但Visual Studio中堅持擰我了之前,我可以輸入完成它
Dim myResult = From d In (From a In db.Members
Join b In db.Payments On a.ID Equals b.Member_Id
Group b.Payment_Date By a.ID, a.First_Name, a.Last_Name Into joke()'<< Here VS insists this is supposed to be the name of a function, and forces me to put these parenthesis no matter what
Select ID, First_Name, Last_Name, Count = joke.Count(), Last_Payment = joke.Max())
我甚至不能得到它讓我甚至開始我讀過我需要做的最大和計數「聚合」部分。
任何提示我要去哪裏出錯?這我感到沮喪了近兩個小時,這麼簡單的東西...