title: How can I fix the 'InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'
body: <p>I am getting the above mentioned error message while retrieving data from my mysql db.</p>
  
  <p>The method workes properly with other tables such as 'users' however, I am not seeing the problem why it's not working with the client table as well.</p>
  
  <p><strong>Client Entity:</strong></p>
  
  <pre><code>public class Client : IEntity&lt;int&gt;
      {
          [Key]
          [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
          public int Id { get; set; }
  
          public string Name { get; set; }
  
          public Entities Entity { get; set; }
  
          public ICollection&lt;ClientBusinessSector&gt; Client_Business_Sectors{ get; set; }
              = new List&lt;ClientBusinessSector&gt;();
  
          [ForeignKey("Country_Id")]
          public Country Country { get; set; }
          public int Country_Id { get; set; }
  
          [ForeignKey("City_Id")]
          public City City { get; set; }
          public int City_Id { get; set; }
  
          public string Address { get; set; }
  
          public ICollection&lt;ClientUser&gt; Client_Users { get; set; }
              = new List&lt;ClientUser&gt;();
  
          public ICollection&lt;ClientService&gt; Client_Services { get; set; }
              = new List&lt;ClientService&gt;();
  
          public enum Entities
          {
              GmbH = 1,
              AG,
              Einzelfirma,
              Kollektivgesellschaft,
              Genossenschaft
          }
      }
  </code></pre>
  
  <p><strong>Controller-Level:</strong></p>
  
  <pre><code>[HttpGet()]
      public async Task&lt;IActionResult&gt; GetAllClients()
      {
          var clientsFromRepo = await _clientRepository.GetAllAsync();
          var clients = Mapper.Map&lt;IEnumerable&lt;ClientDto&gt;&gt;(clientsFromRepo);
  
          return Ok(clients);
      }
  </code></pre>
  
  <p>Repository Methods that are being called from the controller:</p>
  
  <pre><code>public async Task&lt;IEnumerable&lt;TEntity&gt;&gt; GetAllAsync()
          {
              return await _context.Set&lt;TEntity&gt;()
                  .ToListAsync();
          }
  </code></pre>
  
  <p>I need to get a List of clients from my db. Even if it would be an empty list it should return a 200 Ok Status. The repository methods are working properly with other tables but for some reason not with the client table</p>
  
  <p>The error message I get: <em>InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.</em></p>