tags:

views:

72

answers:

2

Hi, 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

A: 

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

Mike Two
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
@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
@Ben, did it again, posted the wrong link. I'm fixing it. Just not my night.
Mike Two
@Mike - No problem, we've all had those days. Thanks for the link, worked perfectly, @Jdidu got there a bit quicker though.
Ben
@Ben - You're welcome. You could still upvote even if you don't accept it :)
Mike Two
A: 

did you see this ?

http://stackoverflow.com/questions/267488/linq-to-sql-multiple-left-outer-joins

JayD
Thanks @Jdidu, worked perfectly
Ben