title: Why is my mysql query always returning an int value instead of a boolean?
body: <p>I am trying to read in the following stored procedure from C#. </p>
  
  <pre><code>DECLARE IsTrue boolean;
  DECLARE IsFalse boolean;
  set IsTrue = true;
  set IsFalse = false;
  SELECT  
       stuff.ID1
      ,stuff.ID2
      ,stuff.ID3
      ,stuff.ID4
        ,CASE  
              WHEN stuff1.ID1 IS NOT NULL THEN IsTrue
              WHEN stuff1.ID1 IS NULL THEN IsFalse
              END AS 'stuff1Column'   
        ,CASE   
              WHEN stuff2.ID1 IS NOT NULL THEN IsTrue
              WHEN stuff2.ID1 IS NULL THEN IsFalse
              END AS 'stuff2Column'   
        FROM myStuff.stuff
        LEFT JOIN myStuff.stuff1 ON stuff.ID1 = myStuff.stuff1.ID1
        LEFT JOIN myStuff.stuff2 ON stuff2.ID1 = myStuff.stuff2.ID1
        ORDER BY stuff.ID1 DESC;
  </code></pre>
  
  <p>Basically in C# I am throwing the following exception. </p>
  
  <pre><code>Object of type 'System.Int32' cannot be converted to type 'System.Boolean'.
  </code></pre>
  
  <p>Even though I am specifying to return a boolean value it is giving me an <code>Int</code> instead. I have also tried using a tinyint(1) for this and it still didn't work.</p>
  
  <p>Here is the class:</p>
  
  <pre><code>public class Stuff {
          private int _ID1;
          private int _ID2;
          private int _ID3;
          private int _ID4;
          private bool _stuff1Column;
          private bool _stuff2Column;
  
      public int ID1 {
          get { return _ID1; }
          set { _ID1 = value; }
      }
      public int ID2 {
          get { return _ID2; }
          set { _ID2 = value; }
      }
      public int ID3 {
          get { return _ID3; }
          set { _ID3 = value; }
      }
      public int ID4 {
          get { return _ID4; }
          set { _ID4 = value; }
      }
      public bool Stuff1Column {  
          get { return _stuff1Column; }
      set { _stuff1Column = value; }
      }
      public bool Stuff2Column {  
          get { return _stuff2Column; }
          set { _stuff2Column = value; }
      }   
  }
  </code></pre>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>My class is trying to read in the <code>stuff1Column</code> and <code>stuff2Column</code> as bool values since that is what the properties are. </p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Here is the C# code to read it in.</p>
  
  <pre><code>public static List&lt;T&gt; Read&lt;T&gt;(T data, string procedure) {
      List&lt;T&gt; collection = new List&lt;T&gt;();
      PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
      List&lt;PropertyInfo&gt; propertiesToSearch = new List&lt;PropertyInfo&gt;();
      foreach (PropertyInfo prop in properties) {
          if (prop.GetCustomAttributes(false).Any(x =&gt; x.GetType() == typeof(DataParameter)))
              propertiesToSearch.Add(prop);
      }
      MySqlConnection connection = new MySqlConnection(Properties.Settings.Default.MySqlConnection);
      MySqlCommand command = new MySqlCommand(procedure, connection);
      command.CommandType = CommandType.StoredProcedure;
      foreach (PropertyInfo property in propertiesToSearch) {
          var parameterName = "@" + property.Name;
          var value = property.GetValue(data, null);
          command.Parameters.AddWithValue(parameterName, value);
      }
      connection.Open();
      MySqlDataReader reader = command.ExecuteReader();
      while (reader.Read()) {
          T item = Activator.CreateInstance&lt;T&gt;();
          foreach (PropertyInfo property in propertiesToSearch) {
              if (reader[property.Name] is MySql.Data.Types.MySqlDateTime) {
                  property.SetValue(item, (DateTime)(MySql.Data.Types.MySqlDateTime)reader[property.Name], null);
              } else {
                  Type test = reader[property.Name].GetType();
                  property.SetValue(item, reader[property.Name], null);
              }
          }
          collection.Add(item);
      }
      reader.Close();
      connection.Close();
      return collection;
  }
  </code></pre>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>I have another table that has a tinyint(1) value stored and the MySqlDataReader automatically interprets that as a boolean value. So I believe it is something to do with it being a stored procedure and the fact that it isn't an actual stored value, possibly?</p>