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

查看:11
本文介绍了将 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 has a ToArray method just for that purpose.

这篇关于将 system.data.linq.binary 转换为 byte[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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