2016-02-06 40 views
0

我知道这可能在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()) 

我甚至不能得到它让我甚至开始我读过我需要做的最大和计数“聚合”部分。

任何提示我要去哪里出错?这我感到沮丧了近两个小时,这么简单的东西...

回答