title: Entity Framework MySQL tinyint(1) System.Boolean.Parse FormatException
body: <p>I'm using <strong>EntityFramework 6</strong> in my C# <strong>model-first</strong> project which using a <strong>MySQL database.</strong>
  Everything was fine and I could generate my database without problem.</p>
  
  <p>Then I modified my <strong>.edmx</strong> file using the designer and here started the problems I have.</p>
  
  <ul>
  <li>First the designer doesn't update the <strong>CSDL content</strong> and the <strong>C-S mapping content</strong> sections of the .edmx file anymore.
  So I updated the content myself and could finally compile the project.</li>
  </ul>
  
  <p>Here's the <strong>.edmx</strong> file as it is right now and what it looks like in the designer:</p>
  
  <p>EDMX File: <a href="http://pastebin.com/Xer9UyNR" rel="noreferrer">http://pastebin.com/Xer9UyNR</a></p>
  
  <p>And here is the link for the designer view:
  <a href="https://i.stack.imgur.com/Vcv9W.png" rel="noreferrer">http://i.stack.imgur.com/Vcv9W.png</a></p>
  
  <ul>
  <li>Second (and most important one), I get a FormatException when EF tries to get a tinyint coming from my database and change its type into a boolean.</li>
  </ul>
  
  <pre>
      à ArmoireOutils.App.OnNavigateMessageHandler(OnNavigateMessage message) dans c:\Users\JB\Desktop\CodingFrance\ArmoireOutils\ArmoireOutils\App.xaml.cs:line 101System.FormatException: String was not recognized as a valid Boolean..
      à System.Boolean.Parse(String value)
      à System.String.System.IConvertible.ToBoolean(IFormatProvider provider)
      à System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
      à MySql.Data.Entity.EFMySqlDataReader.ChangeType(Object sourceValue, Type targetType)
      à MySql.Data.Entity.EFMySqlDataReader.GetValue(Int32 ordinal)
      à System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetUntypedValueDefault(DbDataReader reader, Int32 ordinal)
      à System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
      à System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName)
      à lambda_method(Closure , Shaper )
      à System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
      à lambda_method(Closure , Shaper )
      à System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
      à System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.RowNestedResultEnumerator.MaterializeRow()
      à System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.RowNestedResultEnumerator.MoveNext()
      à System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.TryReadToNextElement()
      à System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.ReadElement()
      à System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.MoveNext()
      à System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
      à System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
      à System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.&amp;lt;GetElementFunction&amp;gt;b__2[TResult](IEnumerable`1 sequence)
      à System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
      à System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
      à System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
      à System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)
      à ArmoireOutils.Services.DataService.GetCupboardByGuid(String guid) dans c:\Users\JB\Desktop\CodingFrance\ArmoireOutils\ArmoireOutils\Services\DataService.cs:line 202
  </pre>
  
  <p>Here is my <strong>GetCupboardByGUID</strong> method:</p>
  
  <pre><code>public Cupboard GetCupboardByGuid(String guid)
      {
          using (var context = new ArmoireOutilsEntities())
          {
              var cupboard = (from a in context.Cupboards
                  where a.GUID.Equals(guid)
                  select a)
                  .Include("ResidentTools")
                  .Include("Tools")
                  .Include("Users") //If I remove this, .SingleOrDefault() works fine.
                  .SingleOrDefault(); //Throw FormatException when getting the User.Active value from the database.
  
              if (cupboard != null)
                  cupboard.RefreshLists();
  
              return cupboard;
          }
      }
  </code></pre>
  
  <p>And here is my User class generated by the .edmx tt:</p>
  
  <pre><code>public partial class User
  {
      public User()
      {
          this.Tools = new ObservableCollection&lt;Tool&gt;();
          this.Cupboards = new ObservableCollection&lt;Cupboard&gt;();
          this.Active = true;
      }
  
      public int Id { get; set; }
      public short Type { get; set; }
      public string Firstname { get; set; }
      public string LastName { get; set; }
      public string Login { get; set; }
      public short Gender { get; set; }
      public short LangId { get; set; }
      public string Photo { get; set; }
      public System.DateTime CreationDate { get; set; }
      public Nullable&lt;System.DateTime&gt; ModificationDate { get; set; }
      public Nullable&lt;System.DateTime&gt; LastConnection { get; set; }
      public Nullable&lt;System.DateTime&gt; DisableDate { get; set; }
      public bool Active { get; set; }
  
      public virtual Lang Lang { get; set; }
      public virtual IList&lt;Tool&gt; Tools { get; set; }
      public virtual IList&lt;Cupboard&gt; Cupboards { get; set; }
  }
  </code></pre>
  
  <p>So I guess EF is iterating over all users from the DB who are in the <strong>cupboarduser</strong> (the table linking a <strong>user</strong> to a <strong>cupboard</strong> for the many-to-many relationship) and when it comes to set the <strong>Active</strong> value for the first user, it gets 1 from the DB getting it as a <strong>String</strong> first and then try to parse that string into a boolean using <strong>System.Boolean.Parse</strong> but thaat method doesn't support numbers like "1" for true (the field in the DB is a <strong>tinyint(1)</strong>).</p>
  
  <p>So why EF is not able to understand it was a tinyint so he can't use it in <strong>System.Boolean.Parse</strong> ?</p>
  
  <p>I tried to regenerate the entire <strong>.edmx</strong> file from the database => Same exception</p>
  
  <p>I tried to regenerate the entire <strong>.edmx</strong> file from scratch => Same exception</p>
  
  <p>I don't understand why because I didn't modify the User model so the <strong>Active</strong> field was already there and was working just fine.</p>
  
  <p>Sorry for the long post and thanks in advance.</p>
  
  <p>Best regards,
  theCivilian</p>