1

我需要将 .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:\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

错误 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=&quot;server=**********;user id=*******;password=*****;database=pki_2010;persistsecurityinfo=True;Treat Tiny As Boolean=false;&quot;" providerName="System.Data.EntityClient" />

有任何想法吗?

4

1 回答 1

1

解决了。

如果有人在我的情况下,这就是解决方案。

1º 将“Treat Tiny As Boolean=false”添加到连接字符串。

2º 构建刷新连接字符串的新值

3º 以 XML 格式打开模型并将列的值设置为“tinyint”(架构应该类似于:

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

4º用设计器打开模型并将列映射到Sbyte

5º 保存并再次构建。

于 2014-05-19T09:10:53.363 回答