使用LINQ将图像存储到SQL:将字节数组或流转换为二进制 [英] Storing images with LINQ to SQL: Converting byte array or stream to Binary

查看:51
本文介绍了使用LINQ将图像存储到SQL:将字节数组或流转换为二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LINQ to SQL,并且我的图像字段被视为Binary.当我需要渲染图像时,将Binary类型转换为byte [](您可以只使用Binary对象的ToArray()方法)没什么大问题,但是有人可以告诉我如何将byte []或将对象流式传输到Binary对象中,这样我就可以将其保存回数据库中.

I am working with LINQ to SQL and my image fields are treated as Binary. It's no big issue to convert the Binary type to byte[] (you can just use the ToArray() method of the Binary object) when I need to render the images, but can someone tell me how to turn either a byte[] or Stream object into the Binary object so I can save it back to the database.

推荐答案

您可以使用像这样:

yourObj.BinaryProperty = new Binary(bytes);

这篇关于使用LINQ将图像存储到SQL:将字节数组或流转换为二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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