Windows Vista Forums

Quick LINQ question
  1. #1


    Leon Mayne Guest

    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

  2. #2


    Leon Mayne Guest

    Re: Quick LINQ question

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

    > 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

Quick LINQ question problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick question MikeB Virtual PC 1 04 Jun 2009
Quick question? venom762 System Security 2 24 Apr 2009
quick question hells bells Sound & Audio 6 16 May 2008
quick question RobB Vista security 1 05 May 2008
Quick question Matt S. \(1033709\) Vista General 3 01 Apr 2006