Search code examples
c#asp.netasp.net-coreasp.net-identityasp.net-core-identity

can not find table for join in asp core identity core


i have 3 table in identitycore 2 in aspcore for Users , Roles and UserRole .

Tabels Image

so i need to fill UserRoleViewModel with all field of 3 tables .

i used this code for join of tabels :

   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
        }

but when i need to for exmaple user.id it not show me property of user tabel . this problem have for all tables .

how can i join this tabels ?


Solution

  • I using this code for return all info about users and they role :

        [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);
        }