Search code examples
mysqlbooleanentityadotinyint

Ado Entity: Treat Tiny as Boolean = false


I need to connect a .net application to a mysql database. When I add the tables to the model, all the columns with the type Tinyint are mapped like boolean.

After Searching in mysql forum, i add "Treat Tiny As Boolean=false" in the connection string. When I refresh the model, nothing changes. If I change the type manually to Sbyte or Int 16 I get the following error.

Error   43  Error 2019: Member Mapping specified is not valid. The type 'Edm.SByte[Nullable=True,DefaultValue=]' of member 'personacion' in type 'Model.perfiles' is not compatible with 'MySql.usmallint[Nullable=True,DefaultValue=]' of member 'personacion' in type 'Model.Store.perfiles'. C:\Proyectos\StatusXMLGenerator\StatusXMLGenerator\StatusXMLGenerator\Model.edmx    474 17  StatusXMLGenerator
Error   42  Error 2019: Member Mapping specified is not valid. The type 'Edm.Int16[Nullable=False,DefaultValue=]' of member 'id_seccion' in type 'Model.formularios' is not compatible with 'MySql.bool[Nullable=False,DefaultValue=]' of member 'id_seccion' in type 'Model.Store.formularios'.    C:\Proyectos\StatusXMLGenerator\StatusXMLGenerator\StatusXMLGenerator\Model.edmx    454 17  StatusXMLGenerator

The error 42 has also an incorrect mapping. It says that the type of the column is Mysql.Bool, but in the databases, I have stored values from 1 to 10, so it should be Mysql.usmallint, like in error 43.

This is my connection string:

<add name="ModelContainer" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=**********;user id=*******;password=*****;database=pki_2010;persistsecurityinfo=True;Treat Tiny As Boolean=false;&quot;" providerName="System.Data.EntityClient" />

Any ideas?


Solution

  • Solved.

    If there is anyone on my situation this is the solution.

    1º Add "Treat Tiny As Boolean=false" to the connection string.

    2º Build to refresh the new value of the connection string

    3º Open the model as XML and set the values of the columns to "tinyint" (The schema should be something like:

    <edmx><schema><entitycontainer><entitytype><property name="..." type="tinyint">...
    

    4º Open the model with the designer and map the columns to Sbyte

    5º Save and build again.