Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing images with LINQ to SQL: Converting byte array or stream to 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.

like image 278
Colin Avatar asked Nov 21 '08 22:11

Colin


1 Answers

You can use the constructor:

public Binary(byte[] value)

like this:

yourObj.BinaryProperty = new Binary(bytes);
like image 138
Panos Avatar answered Sep 22 '22 19:09

Panos