Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Quick LINQ question

Reply
 
Old 10-30-2008   #1 (permalink)
Leon Mayne


 
 

Quick LINQ question

I'm new to LINQ, and so having a small problem trying to left outer join two
generic lists of business objects.

I have a collection of department objects which I want to left join to a
collection of report group objects (based on an integer property called
ReportGroupId) and pull out the department name, id, and the report group
name (empty string if null). I came up with:

Me.gvwDepartments.DataSource = From d In colDepartments _
Group Join r In colReportGroups On d.ReportGroupId Equals
r.ReportGroupId _
Into rgGroup = Group _
From rg In rgGroup _
Select d.DepartmentId, d.Name, ReportGroup = If(rg Is Nothing,
String.Empty, rg.Name)

But this returns an empty set. Does anyone know what I'm doing wrong?


My System SpecsSystem Spec
Old 10-30-2008   #2 (permalink)
Leon Mayne


 
 

Re: Quick LINQ question

"Leon Mayne" <leon@xxxxxx> wrote in message
news:B901B683-FD31-4D60-9554-D4B42CDF543D@xxxxxx
Quote:

> I'm new to LINQ, and so having a small problem trying to left outer join
> two generic lists of business objects.
>
> I have a collection of department objects which I want to left join to a
> collection of report group objects (based on an integer property called
> ReportGroupId) and pull out the department name, id, and the report group
> name (empty string if null). I came up with:
>
> Me.gvwDepartments.DataSource = From d In colDepartments _
> Group Join r In colReportGroups On d.ReportGroupId Equals
> r.ReportGroupId _
> Into rgGroup = Group _
> From rg In rgGroup _
> Select d.DepartmentId, d.Name, ReportGroup = If(rg Is Nothing,
> String.Empty, rg.Name)
>
> But this returns an empty set. Does anyone know what I'm doing wrong?
Nevermind, I just found out I needed to add DefaultIfEmpty to the group
select:

From rg In rgGroup.DefaultIfEmpty

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Quick question? System Security
Quick Question Vista General
Quick question. Vista General
quick question Vista General
A quick question for someone Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46