Reputation: 11644
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
What is the advantage of storing the serialized object in the database over storing its values as multiple strings?
-Ram
Upvotes: 0
Views: 2122
Reputation: 1435
Serialized obejct (XML) If you store the class as XML. You will be able to search the contect of the class by using Xquery. This way is eay way if you want to search(with or without conditions). More over, you can create index over XML column. The XML index will make you application faster.
AS string If you don have bussines login to look at the content of class.
Upvotes: 0
Reputation: 107247
The most common issue with storing an object as a serialized stream is that it is difficult to search the properties of the object once it is stored, whereas if each property of the object is explicitly stored in its own strongly typed column, it can be indexed for searches, and you get the integrity benefit of strongly typed storage.
However, At least if the object is XmlSerialized into an XML column in SQL, you can use technologies such as xquery and OPENXML to ease your searches.
Upvotes: 0
Reputation: 1156
If you store the serialized object into the db:
I you store the multiple strings, you:
I would definitely go for the relational normalized form to store the strings and then build the corresponding class builder in .net.
Upvotes: 3
Reputation: 44605
I would definitely store records and fields and not just a chunk of bytes ( either binary or text or xml ) representing the current status of your object.
it depends of course on the complexity of your business entities ( in your case the Info class ), but I would really avoid saving the serialized version of it in 1 column.
if you explode all properties into fields you can query better for records having certain values and you can handle new columns and releases much easier.
Upvotes: 0