[英]NHibernate: Reading mysql Blob field - value returned as “System.Byte[]”
I have a class with a property:我有一个具有以下属性的 class:
virtual public string Data { get; set; }
example.hbm.xml binds that to: example.hbm.xml 将其绑定到:
<property name="Data" type="string" column="data" ></property>
The table in MySql is created with: MySql 中的表是通过以下方式创建的:
CREATE TABLE `xxx` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`data` blob,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=binary;
I can successfully write to the db and I can see the text in the column written properly.我可以成功写入数据库,并且可以看到列中的文本正确写入。
When I try to read records from this table the value of the 'Data' property is 'System.Byte[]'.当我尝试从此表中读取记录时,“数据”属性的值为“System.Byte []”。 Again this is the value of this property.
这也是该属性的值。 It's type is 'System.String'.
它的类型是'System.String'。
What to do?该怎么办? Thanks in advance for any clues.
提前感谢任何线索。
I tried charset=UTF8 too.我也试过 charset=UTF8 。
I also tried type="StringClob" in the mapping file.我还在映射文件中尝试了 type="StringClob" 。
Thanks Tymek谢谢蒂梅克
You probably need to read and write this as a byte[].您可能需要将其作为 byte[] 进行读写。 So you're property definition would look like this instead:
所以你的属性定义看起来像这样:
public virtual byte[] Data { get; set; }
In addition to this change you will need to change the type in your mapping.除了此更改之外,您还需要更改映射中的类型。 I'm not sure what the type.
我不确定是什么类型。 I think it may be blob.
我认为它可能是blob。
You can easily convert this data to a string if you need to.如果需要,您可以轻松地将此数据转换为字符串。
I'm no MySQL expert, but you probably want the column type to be text
instead of blob
.我不是 MySQL 专家,但您可能希望列类型为
text
而不是blob
。
With that, type="StringClob"
should work这样,
type="StringClob"
应该可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.