【发布时间】:2021-03-06 18:07:44
【问题描述】:
我正在使用带有实体框架 5 的 Asp.Net .Net5
我有 3 张桌子
- aspnetuser
- aspnetroles
- aspnetuserRoles = 链接表
我当前的 LINQ 代码返回来自用户和 userRoles 的所有数据,但没有来自 aspnetrole 表的数据。我希望它返回用户和他们当前分配的角色,以便我可以查看他们是管理员还是标准。
public async Task<IList<User>> GetAllEnabledAccounts()
{
var users = await _context.Users
.Where(u => u.IsEnabled == true)
.Include(r => r.UserRoles)
.ToListAsync();
return users;
}
aspnetuser 表
id | username
--------------
1 | Jim
2 | Harry
aspnet角色
id | name
----------
1 | admin
2 | standard
aspnetuserRoles
userId | roleId
----------------
1 | 1
2 | 2
查询时应该返回用户 Jim 表明他是管理员,而 Harry 表明他是标准帐户。如何输入 LINQ 查询以正确输出信息?
【问题讨论】:
标签: c# asp.net linq asp.net-core .net-5