コード例 #1
0
        public async Task AddAsync(T entity)
        {
            using var context = new GeoToDoDbContext();
            await context.AddAsync(entity);

            await context.SaveChangesAsync();
        }
コード例 #2
0
        public async Task <List <AppRole> > GetRolesByEmail(string email)
        {
            using var context = new GeoToDoDbContext();

            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.Email == email).Select(I => new AppRole
            {
                Id = I.role.Id,
                Name = I.role.Name
            }).ToListAsync());
        }
コード例 #3
0
 public async Task UpdateAsync(T entity)
 {
     using var context = new GeoToDoDbContext();
     context.Update(entity);
     await context.SaveChangesAsync();
 }
コード例 #4
0
 public async Task <T> GetByIdAsync(int id)
 {
     using var context = new GeoToDoDbContext();
     return(await context.FindAsync <T>(id));
 }
コード例 #5
0
 public async Task <T> GetByFilter(Expression <Func <T, bool> > expression)
 {
     using var context = new GeoToDoDbContext();
     return(await context.Set <T>().FirstOrDefaultAsync(expression));
 }
コード例 #6
0
 public async Task <List <T> > GetAllByFilter(Expression <Func <T, bool> > expression)
 {
     using var context = new GeoToDoDbContext();
     return(await context.Set <T>().Where(expression).ToListAsync());
 }
コード例 #7
0
 public async Task <List <T> > GetAllAsync()
 {
     using var context = new GeoToDoDbContext();
     return(await context.Set <T>().ToListAsync());
 }