コード例 #1
0
        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);
        }
コード例 #2
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);
     }
 }
コード例 #3
0
ファイル: BookDeleter.cs プロジェクト: sydykoveldiyar/food
 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("Возникло исключение");
     }
 }
コード例 #4
0
 public void Delete(Category category)
 {
     _context.Remove(category);
 }
コード例 #5
0
ファイル: CommonRepository.cs プロジェクト: luochunjiu/lcj
 /// <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);
 }
コード例 #6
0
        public bool DeleteTransaction(Transaction transaction)
        {
            _context.Remove(transaction);

            return(true);
        }