Linq To Sql使用多个join子句离开了join

时间:2013-02-12 15:29:27

标签: vb.net linq

出于某种原因,我在下面的代码中遇到语法错误。我想要实现的是 带有多个连接条件的LEFT JOIN。语法错误发生在关键字INTO foobar中。 VS 2012表示意外的令牌。任何帮助都会很棒,谢谢!

 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

2 个答案:

答案 0 :(得分:1)

您需要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

答案 1 :(得分:0)

尝试投射f.IDb.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