I am using SQL Server 2008 with NHibernate for an application. In the application I need to create multiple object of a Info class and use it in multiple places. I also need to store that object in the databse.
There are multiple types of Info class.
To store these objects of Info class I have two options
- Store the Serialized obejct of the class
- Store the details of that class as string.
What is the advantage of storing the serialized object in the database over storing its values as multiple strings?
If you store the serialized object into the db:
- You don't have to rebuild it from the partial data (ie. write your own deserializer if the behaviour is default, create objects from the partial data)
- You must create the object "manually"
- May be faster in some cases
- Stores redundant infrastructure data
- You may choose multiple formats (XML, custom format, blobs)
- You have fully prepared serialized objects that are ready to be processed anywhere (sent over the network, stored in a disk)
I you store the multiple strings, you:
- Need to build the objects "manually"
- May use the database data in different scenarios (from .net, to build another structures such as cubes)
- The data is much more compact
- May store the data in a relational normalized form which is (almost) always a good practice
- Query the data
- And the overall more versatile usage of the data.
I would definitely go for the relational normalized form to store the strings and then build the corresponding class builder in .net.