I am trying to return a distinct list – but instead of projecting the Distinct() operator over all the returned fields I only want the Suburb to have the operator applied to it like so lga.Suburb.Distinct() but this does not work – how do I go about this?
Thanks!
Public Function GetLGAForRegion(ByVal region As Integer)
Dim dc As New DataContextDataContext
Dim query = (From lga In dc.tblLGA_Suburbs
Join suburb In dc.tblSuburbs On lga.Suburb Equals suburb.SuburbName
Join regions In dc.tblRegions On suburb.RegionID Equals regions.RegionID
Where (regions.RegionID = region)
Select lga.Suburb.Distinct(), suburb.SuburbID).ToList()
Return query
End Function
Ok – this works 🙂 Thanks for your help!
Dim query = (From lga In dc.tblLGA_Suburbs
Join suburb In dc.tblSuburbs On lga.Suburb Equals suburb.SuburbName
Join regions In dc.tblRegions On suburb.RegionID Equals regions.RegionID
Where (regions.RegionID = region)
Group By lga = lga.Suburb Into g = Group
Order By lga Ascending
Select g.First().lga.Suburb, g.First().suburb.SuburbID).ToList()
You can use GroupBy like this
in query style