开发者

NHibernate: Reading mysql Blob field - value returned as "System.Byte[]"

I have a class with a property:

virtual public string Data { get; set; }

example.hbm.xml binds that to:

<property name="Data" type="string" column="data" ></property>

The table in MySql is created with:

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[]'. Again this is the value of this property. It's type is 'System.String'.

Wh开发者_Go百科at to do? Thanks in advance for any clues.

I tried charset=UTF8 too.

I also tried type="StringClob" in the mapping file.

Thanks Tymek


You probably need to read and write this as a 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.

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.

With that, type="StringClob" should work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜