简体   繁体   English

如何在实体框架中以字符串形式获取mysql中的char列类型

[英]how to get char column type in mysql as string in entity framework

Created entity model from MySql database. 从MySql数据库创建实体模型。 The table column of type char(16) is converted as System.Guid in entity. char(16)类型的表列在实体中转换为System.Guid。

All the code is based on string as i have used Sql Server for the application before. 所有代码都是基于字符串的,因为我之前已将Sql Server用于该应用程序。 Now after converting the entity from MySql am having this problem. 现在从MySql转换实体后出现此问题。 All over the code i have custome objects where i have used these as strings. 在所有代码中,我都有custome对象,在其中我已将它们用作字符串。

Tried to use some tricks from the articles i read but no use. 尝试使用我阅读的文章中的一些技巧,但没有用。 done using the old connector/net but no use. 使用旧的连接器/网络完成,但无济于事。

How can i get char type column in mySql as string? 我怎样才能在MySQL中将char类型列作为字符串?

MySQL and C# convert types different. MySQL和C#的转换类型不同。 Example: 例:

varchar will be returned as a string for C# varchar将作为string返回给C#

char will be returned as a System.GUID char将作为System.GUID返回

blob will be returned as a byte[] Blob将作为byte[]返回

As far as I know there is no such thing to convert them. 据我所知,没有这样的东西可以转换它们。 Maybe a little workaround for you would be converting them in the set 也许您可以通过一些解决方法将它们转换为set

      [NotMapped]
      private string _converter { get; set; }
      [Column(TypeName = "char"), StringLength(16)] 
      public string MyProperty 
      {
       get
       {
         return this._converter;
       }
       set
       {
         this._converter = Convert.ToString(value);
       }
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM