0

I have a problem where I can not Delete or update entity in asp.net I want to automap objects using "AutoMapper" framework, but when I try to do it, it's cause error and I don't know why

        /// Method for deleting entity in the Generic Repository
        public void Delete<T>(int id) where T : class
        {
            try
            {
                var entity = _context.Set<T>().Find(id);
                _context.Set<T>().Remove(entity);
                _context.SaveChanges();
            }
            catch
            {
            /// Expection error
            }
        /// Interface
        void Delete<T>(int id) where T : class;
        /// I have use the AutoMapper framework for mapping objects
        /// Also Mapper and Repository (interface) are injected in the constructor
        public void Delete(IUser entity)
        {
            Repository.Delete(_mapper.Map<UserEntity>(entity));
        }
        /// Function for delete
Tony Vargek
  • 13
  • 1
  • 5

1 Answers1

0

You need to pass the type of the entity you are deleting. It needs to be something like this:

Repository.Delete<UserEntity>(entity.Id);
Mocas
  • 1,403
  • 13
  • 20