Linq :
from a in SysUserRoles
join b in SysUserInfo.DefaultIfEmpty()
on a.UserId equals b.UserId
select a
生成的Sql:
SELECT [t0].[ID], [t0].[UserId], [t0].[RoleId], [t0].[CreateDate], [t0].[CreateUser], [t0].[CreateIp]
FROM [SysUserRole] AS [t0]
INNER JOIN ((
SELECT NULL AS [EMPTY]
) AS [t1]
LEFT OUTER JOIN [SysUserInfo] AS [t2] ON 1=1 ) ON [t0].[UserId] = [t2].[UserId]
为什么SysUserInfo和自己Left join 而不是直接SysUserRole Left Join呢
inner join(等值连接) 只返回两个表中联结字段相等的行,left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录
嗯是啊,为什么linq生成的语句,SysUserInfo和自己左连接,没有和SysUserRole左连接