コード例 #1
0
        public async Task <bool> DeleteAsync(int id)
        {
            var entity = await _context.FindAsync <T>(id);

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

            return(true);
        }
コード例 #2
0
        public async Task DeleteAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                _context.Remove(entity);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw new Exception($"{nameof(entity)} could not be saved: {ex.Message}");
            }
        }