コード例 #1
0
        public async Task <TEntityViewModel> GetAsync(int id, params Expression <Func <TEntity, object> >[] includeProperties)
        {
            var query  = _db.Set <TEntity>().Where(x => x.Id == id);
            var mapped = query.ProjectTo <TEntityViewModel>(includeProperties);

            return(await mapped.FirstOrDefaultAsync());
        }
コード例 #2
0
        public async Task <TEntity> DeleteAsync(int id)
        {
            var entity = await _db.Set <TEntity>().FirstOrDefaultAsync(x => x.Id == id);

            _db.Remove(entity);
            await _db.SaveChangesAsync();

            return(entity);
        }
コード例 #3
0
ファイル: EntityUpdater.cs プロジェクト: anapadiuk/mm-api
        public async Task <TEntity> UpdateAsync(int id, TEntityBindingModel model)
        {
            var entity = await _db.Set <TEntity>().FirstOrDefaultAsync(x => x.Id == id);

            var dest = (TEntity)Mapper.Map(model, entity, typeof(TEntityBindingModel), typeof(TEntity));

            _db.Update(dest);
            await _db.SaveChangesAsync();

            return(dest);
        }
コード例 #4
0
        public async Task <IEnumerable <TEntityViewModel> > GetAsync(
            Expression <Func <TEntity, bool> > where,
            params Expression <Func <TEntity, object> >[] includeProperties)
        {
            var query = _db.Set <TEntity>().AsQueryable();

            if (where != null)
            {
                query = query.Where(where);
            }

            var mapped = query.ProjectTo <TEntityViewModel>(includeProperties);

            return(await mapped.ToListAsync());
        }