将system.data.linq.binary转换为byte [] [英] convert system.data.linq.binary to byte[]

查看:87
本文介绍了将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.datalinq.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆