Search code examples
c#oracle-databasexml-serializationodp.net

Store Serialized Objects into Oracle DB (Preferably XML) C#


Before I start writing code to handle this I want a feedback about what is the best way to go.

The background behind this problem is that I want to create some sort of storage for a C# object just in case the program crashes and the data is lost.

I want to store a SERIALIZED object into the database and then be able to query it from ODP.NET w/ successfully deserializing it and casting it into the same object.

By the way, the data for the serialized object would be around 50 MEGABYTES after serialization.

Usage: For every day there will be a serialized object stored, and be retrieved up to 10 times per day.

My questions are, if anyone has done this before;

  • What is the best data type to use to store it? (I was thinking of serializing into flat XML and storing it as a CLOB/BLOB string)
  • What is the fastest method for it, or are there any steps I need to be aware of to make it efficient?
  • If I use the C# Serialize and Deserialize, am I guaranteed that the object will be the same (pretty much asking how reliable XML serialize is in C#, I was contemplating using JSon instead)

Let me know what you guys think!

Thanks!


Solution

  • If your object is mostly text, after you serialize the data (XML or JSON would be fine, assuming all of the properties truly are serializable), I'd recommend compressing your data into a byte array and storing it as binary. When you retrieve it, you'd just decompress it and then deserialize it. Text zips down very nicely, especially XML, so you might get that 50MB down to 10MB or less.

    Based on your comment, zipping would absolutely be worthwhile. And if you're only adding 10MB or so per day, it sounds like it wouldn't negatively affect your database - just a few GB per year.