左外连接linq中的3个表到sql

时间:2013-02-28 07:10:45

标签: linq join

我试图在linq中编写一个查询,我加入3个表格,并用字符串“ANY”填写空值,但这不会发生需要一些帮助,请我是新来的。

我尝试过这样的事情......

var results = from user in allusers
              join building in allbuildings where building.buildingid equals user.buildingid
              into BuildingAndUsers.FirstorDefault(new allbuildings{BuildingName="ANY" BuildingID=0})
              from blah in BuildingAndUsers
              join Site in AllSites where ....

1 个答案:

答案 0 :(得分:1)

类似的东西:

var results = 
      from user in allusers
      join building in allbuildings on building.buildingid equals user.buildingid
          into BuildingAndUsers 
      from buildingAndUser in BuildingAndUsers.DefaultIfEmpty(new allbuildings { BuildingName="ANY", BuildingID=0 })
      join Site in AllSites on ....
          into BuildingAndUsersAndSites
      from buildingAndUsersAndSite in BuildingAndUsersAndSites.DefaultIfEmpty()
      select ...