Reputation: 588
I know this has probably been answered a dozen times in C#, but I'm having difficulty finding a simple solution in VB.Net (Everyone else is doing multiple joins with groups and all this other junk I don't need and can't effectively filter out for my solution).
Essentially, I'm trying to write the following (simple) SQL query into LINQ on 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
I've tried and got this far, but Visual Studio insists on screwing me over before I can finish typing it out
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())
I can't even get it to let me even start on the "Aggregate" portion I've read I will need to do the Max and Count.
Any hints on where I'm going wrong? This has frustrated me for nearly two hours for something so simple...
Upvotes: 0
Views: 1078
Reputation: 588
Found answer in
How do I use "Into" LINQ expression in VB.NET?
Apparently I need to do = Group
so it doesn't think it's a function. :facepalm:
Upvotes: 1