将system.data.linq.binary转换为byte [] [英] convert system.data.linq.binary to byte[]
本文介绍了将system.data.linq.binary转换为byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将字节存储在数据库表中.当我使用Linq 2 sql检索它时,在system.data.linq.Binary
中得到返回类型.
I am storing bytes in a database table. When I retrieve it with Linq 2 sql I get the return type in system.data.linq.Binary
.
我无法将system.data.linq.binary
转换为字节数组(byte[]
).
I am not able to convert the system.data.linq.binary
to byte array(byte[]
).
我如何转换它?
///my datacontext
var db = new db();
//key is an value from user
var img = from i in db.images
where i.id == key
select i.data;
i.data
在linq.binary
中,我希望它在byte[]
中.
the i.data
is in linq.binary
I want it to be in byte[]
.
我尝试使用(byte[])img
,但是没有用.
I tried with (byte[])img
but it did not work.
推荐答案
您是否尝试过在i.data
上调用ToArray()
?
Have you tried calling ToArray()
on i.data
?
var img = from i in db.images
where i.id == key
select i.data.ToArray();
System.Data.Linq.Binary
为此具有一个ToArray
方法.
这篇关于将system.data.linq.binary转换为byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文