Ado实体:将Tiny视为Boolean = false [英] Ado Entity: Treat Tiny as Boolean = false
问题描述
我需要将.net应用程序连接到mysql数据库。当我将表添加到模型中时,所有类型为Tinyint的列都被映射为布尔值。
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.
在mysql论坛中搜索后,我添加了 Treat Tiny As Boolean =连接字符串中的 false。当我刷新模型时,没有任何变化。如果我将类型手动更改为Sbyte或Int 16,则会出现以下错误。
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
错误42的映射也不正确。它说该列的类型是Mysql.Bool,但是在数据库中,我存储了1到10的值,所以它应该是Mysql.usmallint,就像错误43一样。
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.
这是我的连接字符串:
<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" />
有什么想法吗?
推荐答案
已解决。
如果遇到我的情况,这就是解决方案。
If there is anyone on my situation this is the solution.
1º向连接字符串中添加 Treat Tiny As Boolean = false。
1º Add "Treat Tiny As Boolean=false" to the connection string.
2º构建以刷新连接字符串的新值
2º Build to refresh the new value of the connection string
3º以XML格式打开模型并将列的值设置为 tinyint(架构应类似于:
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º打开设计器,并将列映射到Sbyte
4º Open the model with the designer and map the columns to Sbyte
5º保存并重新构建。
这篇关于Ado实体:将Tiny视为Boolean = false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!