我有
Users(Id, Name)
UserClaims(Id, UserId, Type, Value)
UserLogins(ProviderName, ProviderKey, UserId)
UserRoles(UserId, RoleId)
Roles(Id, Name)
如何在单个查询中按名称选择具有所有相关实体的用户?
答案 0 :(得分:1)
听起来你只想加入相关的表格,如果是这样的话,也许这就是你要找的东西:
SELECT *
FROM Users U
INNER JOIN UserClaims UC ON U.Id = UC.UserId
INNER JOIN UserLogins UL ON U.Id = UL.UserId
INNER JOIN UserRoles UR ON U.Id = UR.UserId
INNER JOIN Roles R ON R.Id = UR.RoleId
WHERE U.Name = 'name' -- or @name or whatever way you pass the variable...