无法从 Asp.net 中的用法推断出方法的类型参数

The type arguments for method cannot be inferred from the usage in Asp.net

我遇到无法删除或更新 asp.net 中的实体的问题 我想使用“AutoMapper”框架自动映射对象,但是当我尝试这样做时,它会导致错误,我不知道为什么

        /// 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

您需要传递要删除的实体的类型。 它需要是这样的:

Repository.Delete<UserEntity>(entity.Id);