找不到 table 加入 asp 核心身份核心
can not find table for join in asp core identity core
我在 aspcore 的 identitycore 2 中有 3 table Users
, Roles
和 UserRole
.
所以我需要用 3 tables 的所有字段填充 UserRoleViewModel
。
我使用此代码连接表格:
public class ApplicationUserManager : UserManager<User>,
IApplicationUserManager
{
private readonly IUnitOfWork _uow;
_passwordValidators;
private readonly IServiceProvider _services;
private readonly DbSet<User> _users;
private readonly DbSet<Role> _roles;
private readonly DbSet<UserRole> _userRoles;
private readonly IApplicationUserStore _userStore;
IUnitOfWork uow,
IUsedPasswordsService usedPasswordsService)
: base((UserStore<User, Role, ApplicationDbContexct, int, UserClaim, UserRole, UserLogin, UserToken, RoleClaim>)storer)
{
_users = uow.Set<User>();
_roles = uow.Set<Role>();
_userRoles = uow.Set<UserRole>();
}
public List<UserRoleViewModel> FindUserRole()
{
var userinfo=from users in Users
join userRole in _userRoles on users
}
但是当我需要 user.id
时,它不会显示用户 tabel 的 属性。这个问题对所有 tables 都有。
我怎样才能加入这个表格?
我将此代码用于 return 所有关于用户及其角色的信息:
[HttpGet("UserList")]
public IEnumerable<User> UserList()
{
return _applicationUserManager.Users.ToList();
}
[HttpGet("Roles")]
public async Task<IActionResult> Role()
{
List<UserRoleViewModel> URVM = new List<UserRoleViewModel>();
foreach (var item in UserList())
{
var users = await _applicationUserManager.FindUserById(item.Id);
var roles = await _applicationUserManager.GetRolesAsync(users);
var roleName = await _applicationRoleManager.FindRoleByNameList(roles[0]);
URVM.Add(new UserRoleViewModel
{
Id = users.Id,
Email = users.Email,
BirthDate = users.BirthDate,
CreatedDateTime = users.CreatedDateTime,
FirstName = users.FirstName,
IsActive = users.IsActive,
PhoneNmuberConfirmed=users.PhoneNumberConfirmed,
IsEmailPublic = users.IsEmailPublic,
LastName = users.LastName,
TwoFactorEnabled = users.TwoFactorEnabled,
EmailConfirmed = users.EmailConfirmed,
LockoutEnabled = users.LockoutEnabled,
LastVisitDateTime = users.LastVisitDateTime,
Location = users.Location,
PhotoFileName = users.PhotoFileName,
RoleLevel = roleName.RoleLevel,
Description = roleName.Description,
roleId = roleName.Id
});
}
return Ok(URVM);
}
我在 aspcore 的 identitycore 2 中有 3 table Users
, Roles
和 UserRole
.
所以我需要用 3 tables 的所有字段填充 UserRoleViewModel
。
我使用此代码连接表格:
public class ApplicationUserManager : UserManager<User>,
IApplicationUserManager
{
private readonly IUnitOfWork _uow;
_passwordValidators;
private readonly IServiceProvider _services;
private readonly DbSet<User> _users;
private readonly DbSet<Role> _roles;
private readonly DbSet<UserRole> _userRoles;
private readonly IApplicationUserStore _userStore;
IUnitOfWork uow,
IUsedPasswordsService usedPasswordsService)
: base((UserStore<User, Role, ApplicationDbContexct, int, UserClaim, UserRole, UserLogin, UserToken, RoleClaim>)storer)
{
_users = uow.Set<User>();
_roles = uow.Set<Role>();
_userRoles = uow.Set<UserRole>();
}
public List<UserRoleViewModel> FindUserRole()
{
var userinfo=from users in Users
join userRole in _userRoles on users
}
但是当我需要 user.id
时,它不会显示用户 tabel 的 属性。这个问题对所有 tables 都有。
我怎样才能加入这个表格?
我将此代码用于 return 所有关于用户及其角色的信息:
[HttpGet("UserList")]
public IEnumerable<User> UserList()
{
return _applicationUserManager.Users.ToList();
}
[HttpGet("Roles")]
public async Task<IActionResult> Role()
{
List<UserRoleViewModel> URVM = new List<UserRoleViewModel>();
foreach (var item in UserList())
{
var users = await _applicationUserManager.FindUserById(item.Id);
var roles = await _applicationUserManager.GetRolesAsync(users);
var roleName = await _applicationRoleManager.FindRoleByNameList(roles[0]);
URVM.Add(new UserRoleViewModel
{
Id = users.Id,
Email = users.Email,
BirthDate = users.BirthDate,
CreatedDateTime = users.CreatedDateTime,
FirstName = users.FirstName,
IsActive = users.IsActive,
PhoneNmuberConfirmed=users.PhoneNumberConfirmed,
IsEmailPublic = users.IsEmailPublic,
LastName = users.LastName,
TwoFactorEnabled = users.TwoFactorEnabled,
EmailConfirmed = users.EmailConfirmed,
LockoutEnabled = users.LockoutEnabled,
LastVisitDateTime = users.LastVisitDateTime,
Location = users.Location,
PhotoFileName = users.PhotoFileName,
RoleLevel = roleName.RoleLevel,
Description = roleName.Description,
roleId = roleName.Id
});
}
return Ok(URVM);
}