Search code examples
databaseserializationvarbinary

Serializing an object and storing it to a varbinary field in a DB


I can serialize an object to a file using:

var writeStream = File.Open("l.osl", FileMode.Create);
var bformatter = new BinaryFormatter();
bformatter.Serialize(writeStream, l);

What I am trying to do is instead of writing it to a file, write it to a DB varbinary field. I assume that I have to change writeStream to something else, but what? Can I just put an object in there and there insert that object into the DB (I'm using LINQ).

Will this work?

PS: I have looked around and can't find any solid examples.


Solution

  • Kind of close to this:

    Storing C# data structure into a SQL database