Storing images with LINQ to SQL: Converting byte array or stream to Binary
-
10-07-2019 - |
Question
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.
Solution
You can use the constructor:
public Binary(byte[] value)
like this:
yourObj.BinaryProperty = new Binary(bytes);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow