public async Task <List <AppRole> > GetRolesByUserName(string userName)
        {
            //efcore 5.0 include(I=>I.AppRole.where(a=>a.roleName==name))

            using var context = new UdemyJwtContext();
            return(await context.AppUsers.Join(context.AppUserRoles, u => u.Id, ur => ur.AppUserId, (user, userRole) => new
            {
                user = user,
                userRole = userRole
            }).Join(context.AppRoles, two => two.userRole.AppRoleId, r => r.Id, (twoTable, role) => new
            {
                user = twoTable.user,
                userRole = twoTable.userRole,
                role = role
            }).Where(I => I.user.UserName == userName).Select(I => new AppRole
            {
                Id = I.role.Id,
                Name = I.role.Name
            }).ToListAsync());
        }
示例#2
0
 public async Task Update(TEntity entity)
 {
     using var context = new UdemyJwtContext();
     context.Update(entity);
     await context.SaveChangesAsync();
 }
示例#3
0
 public async Task <TEntity> GetById(int id)
 {
     using var context = new UdemyJwtContext();
     return(await context.Set <TEntity>().FindAsync(id));
 }
示例#4
0
 public async Task <TEntity> GetByFilter(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new UdemyJwtContext();
     return(await context.Set <TEntity>().FirstOrDefaultAsync(filter));
 }
示例#5
0
 public async Task <List <TEntity> > GetAllByFilter(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new UdemyJwtContext();
     return(await context.Set <TEntity>().Where(filter).ToListAsync());
 }
示例#6
0
 public async Task <List <TEntity> > GetAll()
 {
     using var context = new UdemyJwtContext();
     return(await context.Set <TEntity>().ToListAsync());
 }