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()); }
public async Task Update(TEntity entity) { using var context = new UdemyJwtContext(); context.Update(entity); await context.SaveChangesAsync(); }
public async Task <TEntity> GetById(int id) { using var context = new UdemyJwtContext(); return(await context.Set <TEntity>().FindAsync(id)); }
public async Task <TEntity> GetByFilter(Expression <Func <TEntity, bool> > filter) { using var context = new UdemyJwtContext(); return(await context.Set <TEntity>().FirstOrDefaultAsync(filter)); }
public async Task <List <TEntity> > GetAllByFilter(Expression <Func <TEntity, bool> > filter) { using var context = new UdemyJwtContext(); return(await context.Set <TEntity>().Where(filter).ToListAsync()); }
public async Task <List <TEntity> > GetAll() { using var context = new UdemyJwtContext(); return(await context.Set <TEntity>().ToListAsync()); }