I'm trying to show a Duplicate Record error message in an WebAPI service. I'm using .net5 and mysql. I cannot seem to find a way to pull the duplicateEntry message from the exception response. I'd like to key in on the ErrorCode field and use this to tailor a response to the user. I can see the Message property, but cannot figure out how to access the innerException.
        {
            try
            {
                module.Id = Guid.NewGuid();
                await _moduleRepository.Add(module);
                await _uow.CompleteAsync();
                return true;
            }
            catch (DbUpdateException ex)
            {
                logger.LogWarning("Module - Add Error: " + ex.Message);
                return false;
            }
            
            
        } 
