链接到SQL Join语句或子句

时间:2010-03-06 16:27:54

标签: c# linq linq-to-sql linq-to-entities linq-to-objects

我必须遵循我想要转换为LINQ的SQL语句

Select
  F.FooName
  B.BarName
From Foo F
Inner Join Bar B on B.BarName = F.FooName OR B.BarName + 'hello' = F.FooName

我在使用AND子句的多个条件中看到了链接中的内连接,但没有使用OR 以下就我而言

var myresult = from f in Foo
               join b in Bar
                   on new {Name = B.BarName, NamePlus = B.BarName + "hello"} equals
                      new {Name = F.FooName, NamePlus = F.FooName}
               select new { f, b }

显然这是不对的。任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:3)

var myresult = from f in foo
               from b in bar
               where b.BarName == f.FooName ||
                     b.BarName + 'hello' == F.FooName
               select new {f, b};