public bool Delete(int id) { try { var entity = _dbSet.SingleOrDefault(x => x.Id == id); if (entity == null) { throw new ArgumentNullException(nameof(entity), "user couldn't find for deleting"); } _ctx.Set(CurrentType).Attach(entity); _ctx.Entry<T>(entity).State = System.Data.Entity.EntityState.Deleted; _dbSet.Remove(entity); if (_ctx.SaveChanges() > 0) { return true; } throw new ArgumentException("Error while deleting data"); } catch (Exception e) { // log Console.WriteLine(e); throw; } }
protected BaseBL(BbsContext context) { _ctx = context; _dbSet = context.Set<T>(); CurrentType = typeof(T); }