Пример #1
0
        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;
            }

        }
Пример #2
0
 protected BaseBL(BbsContext context)
 {
     _ctx = context;
     _dbSet = context.Set<T>();
     CurrentType = typeof(T);
 }