Suppose you have a tblRoom and tblUserInfo. Now, you need to select all the rooms regardless of whether the room has user information or not. This calls for a LEFT JOIN which will select everything from the LEFT side (the room side) regardless of the join on the right side. Here is the example.
假如你有两张表tblRoom(房 间表)和tblUserInfo(住户表)。
现在你需要检索出所有房间的信息,而不管这个房间是否有人居住。这就需要进行LEFT JOIN(左外连接),左外连接会检索出LEFT JOIN左边表中的所有行,而不管右边的表是否有匹配项。下面是一个例子:
var list = from r in dc.tblRooms join ui in dc.tblUserInfos on r.UserName equals ui.UserNameinto userrooms from ur in userrooms.DefaultIfEmpty() select new { FirstName = (ur.FirstName == null) ? "N/A" : ur.FirstName, LastName = (ur.LastName == null) ? "N/A" : ur.LastName, RoomName = r.Name };