我需要连接一个。net应用程序到mysql数据库。当我将表添加到模型中时,所有类型为Tinyint的列都像布尔值一样被映射。
在mysql论坛中搜索后,我在连接字符串中添加了"Treat Tiny As Boolean=false"。当我刷新模型时,没有任何变化。如果我手动将类型更改为Sbyte或Int 16,我会得到以下错误:
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:ProyectosStatusXMLGeneratorStatusXMLGeneratorStatusXMLGeneratorModel.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:ProyectosStatusXMLGeneratorStatusXMLGeneratorStatusXMLGeneratorModel.edmx 454 17 StatusXMLGenerator
错误42也有一个不正确的映射。它说列的类型是Mysql。Bool,但在数据库中,我已经存储了从1到10的值,所以它应该是Mysql。Usmallint,如错误43.
我的连接字符串:
<add name="ModelContainer" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=MySql.Data.MySqlClient;provider connection string="server=**********;user id=*******;password=*****;database=pki_2010;persistsecurityinfo=True;Treat Tiny As Boolean=false;"" providerName="System.Data.EntityClient" />
任何想法?
已解决。
如果有人和我的情况一样,这就是解决办法。
1º在连接字符串中添加"Treat Tiny As Boolean=false"。
2º构建以刷新连接字符串
的新值3º以XML形式打开模型,并将列的值设置为"tinyint"(模式应该类似于:
<edmx><schema><entitycontainer><entitytype><property name="..." type="tinyint">...
4º用设计器打开模型并将列映射到Sbyte
5º保存并重新构建