gh9
gh9

Reputation: 10703

Linq To Sql left join using multiple join clauses

For some reason I am getting a syntax error on the below code. What I am trying to achieve is A LEFT JOIN with MULTIPLE JOIN CLAUSES. The syntax error occurs at the Keyword INTO foobar. VS 2012 says unexpected Token. Any help would be great, thank you !

 Dim results = From f In foo _
                   Join b In bar On new with {f.Type,f.ID} Equals New With {"Test",b.ID} into fooBar _
                   from x in foobar.DefaultEmpty() _ 
                   Where foo.id = 1

Upvotes: 0

Views: 540

Answers (2)

D Stanley
D Stanley

Reputation: 152654

You want a Group Join:

Dim results = From f In foo _
               Group Join b In bar On 
                   New With {f.Type,f.ID} Equals New With {"Test",b.ID} _
                   Into fooBar = Group _
               from x in foobar.DefaultEmpty() _ 
               Where foo.id = 1

Upvotes: 1

spajce
spajce

Reputation: 7092

Try to cast the f.ID or b.ID

 Dim results = From f In foo _
                   Join b In bar On new with {f.Type, CInt(f.ID)} Equals New With {"Test", CInt(b.ID)} into fooBar _
                   from x in foobar.DefaultEmpty() _ 
                   Where foo.id = 1

Upvotes: 0

Related Questions