// Удаление сущности
        public void Remove(int id)
        {
            // Каждая таблица - объект DbSet со свойством Local. Возвращаем из кэша сущность, либо создаем ее
            var item = set.Local.FirstOrDefault(i => i.Id == id) ?? new T {
                Id = id
            };

            db.Remove(item);
            if (AutoSaveChanges)
            {
                db.SaveChanges();
            }
        }
示例#2
0
        public async Task <IActionResult> DeleteBookstore(int id)
        {
            var bookstore = await context.Bookstores.FindAsync(id);

            if (bookstore == null)
            {
                return(NotFound());
            }
            context.Remove(bookstore);
            await context.SaveChangesAsync();

            return(Ok(id));
        }
示例#3
0
        public bool Delete(TEntity entity)
        {
            try
            {
                _context.Remove(entity);

                _context.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }