public async Task <bool> DeleteById(long id) { var entity = await _dbContext.Set <TEntity>().FirstAsync(x => x.Id == id); _dbContext.Remove(entity); return((await _dbContext.SaveChangesAsync()) > 0); }
public bool Delete <TEntity>(object id) where TEntity : class { try { _dbContext.Remove(_dbContext.Find <TEntity>(id)); _dbContext.SaveChanges(); return(true); } catch (Exception e) { throw new InvalidDataException(e.Message); } }
public async Task Execute(IJobExecutionContext context) { try { using (EFDbContext _context = new EFDbContext()) { var books = _context.Books.Include(b => b.Table); foreach (var book in books) { TimeSpan ts = DateTime.Now - book.BookDate; if (ts.TotalMinutes >= 30 && book.Table.Status == TableStatus.Booked) { book.Table.Status = TableStatus.Free; _context.Remove(book); } } await _context.SaveChangesAsync(); } } catch (Exception) { throw new Exception("Возникло исключение"); } }
public void Delete(Category category) { _context.Remove(category); }
/// <summary> /// 删除记录 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="entity"></param> /// <returns></returns> public bool Delete <TEntity>(TEntity entity) where TEntity : class { _dbContext.Remove(entity); return(_dbContext.SaveChanges() > 0); }
public bool DeleteTransaction(Transaction transaction) { _context.Remove(transaction); return(true); }