0

Im trying to use LINQ to query Objets. I'm doing the following:

Dim myList As Generic.List(Of MyItem) = (From ThisItem In LinqToSqlObject.Items _
                                         Join Folder In LinqToSqlObject.Folders _
                                         On Folder.Id Equals Item.Id _
                                         Join thisParentItem As Item In LinqToSqlObject.Items _
                                         On thisParentItem.Id Equals Item.ItemId _
                                         Select New MyItem With {.ItemName = Item.Name, _
                                         .ParentItemName = thisParentItem.Name}).ToList

This however will not return any item that has a ParentItemId of null. I am trying to do a left join so as to return all "Item" regardless of whether it has a parent or not. I am aware that this is feasible in C# by adding an "into X" on the join, and selecting from X.DefaultIfEmpty(), this however does not appear to work in VB.Net.

Does anyone know how to do this?

Thanks

Mike Two
  • 44,935
  • 9
  • 80
  • 96
Ben
  • 3,926
  • 12
  • 54
  • 87
  • possible duplicate of [Linq to Sql: Multiple left outer joins](http://stackoverflow.com/questions/267488/linq-to-sql-multiple-left-outer-joins) – Matt Apr 06 '14 at 10:13

1 Answers1

0

Try this example.

Edit: Oops missed the vb.net requirement, sorry.

Try this answer to a similar question.

Edit of the Edit (I'm on a roll)

Posted a link to the wrong answer, but same question.

The vb.net answer is here

Community
  • 1
  • 1
Mike Two
  • 44,935
  • 9
  • 80
  • 96
  • Hi @Mike, I have seen this (excellent website), but as stated in the question, i am aware that this is possible in C# (as per the code in your link), but i cant get it to work in VB.Net. – Ben Mar 10 '10 at 17:09
  • @Ben - sorry, I did miss that in the first pass. I've updated the answer with a vb.net based link. Sorry about that. – Mike Two Mar 10 '10 at 17:11
  • @Ben, did it again, posted the wrong link. I'm fixing it. Just not my night. – Mike Two Mar 10 '10 at 17:12
  • No problem, we've all had those days. Thanks for the link, worked perfectly, @Jdidu got there a bit quicker though. – Ben Mar 10 '10 at 17:19