.NET Serialization: saving your object in a database... is this better than saving data in columns?

Posted on 2011-09-09
Last Modified: 2012-06-27
Hi, I have a question... possibly a stupid question, I'm not sure.

But, just started dabbling with serialization because I've created a website which savesinformation related to the user. So, in order to work with this data, I extract the user's information from the database, put it into my User object and then perform manipulations.

But, ultimately the data is stored in a standard table in an oracle database. So, of course I've just realised and managed to get working, the process of saving that data in the oracle table (BLOB field) as a serialized object. Then I can extract that serialized object directly without having to extract the information column by column.

So... knowing little about this and not really being able to see the possible difficulties down the road... I am just wondering to myself... why bother storing the data in standard format at all? Why not just do away with all the columns and only store the User object?

So why not? Well, I guess the obvious answer is that you can't run simple queries on your database anymore... and you're going to want to do that. But, I am just wondering whether I'm better off, not only storing the data in a standard column, but then including a User column at the end where I store my User object also. Then I can more or less build my code around extracting that object when I want to deal with a user's information... instead of extracting every column and building my Task object column by column in code.

What do the experts say?! What's the standard way people do these types of things?
Question by:AidenA
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 36509530
Well, depends - how big is your application, how many users you;ll store, how often you;ll need to search in... you name it.

Technically it is possible. But from architecture point of view - depends on many things.


Ivo Stoykov

Author Comment

ID: 36509553
what do you mean technically it's possible? I just tested and was able to store a user object in a blob along with all the other data and then extract it again. So... it's possible yes. But do companies generally do something like this... and if not, then why not?

There is a bit of overhead with serialization, so that might be a reason. But binary formatter is very fast, and I don't think it would affect things in my case. There will only be about 100 users using the site and not in with heavy usage either
LVL 22

Assisted Solution

by:Ivo Stoykov
Ivo Stoykov earned 50 total points
ID: 36509587
technically it's possible means
> ... able to store a user object in a blob along with all the other data and then extract it again.

> do companies generally do something like this... and if not, then why not?
Decision is made upon many considerations. You cannot just ask "to store or not to store?"
These are fundamental questions about database storage. Each decision has pro and cons and this is why some companies do other - don't.

The best answer for me is - test it, measure it and you'll get the answer.


Ivo Stoykov
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Author Comment

ID: 36509615
Yeah but that's not really a useful answer if you don't mind me saying so :(

Here is an answer... just saw this article

So based on that, I'd be inclined to say that it is a bad idea to store your objects in a serialized way. (1) As I mentioned, you can't run queries easily on it anymore (2) As the article mentions, if you need to make a small change to the data, this now requires a large change as the entire blob has to be updated... so there is loss of functionality here and loss of performance (although perhaps easier to code with).

If you were to include a blob with your object along with all the other data then in fact now it's worse because you'd have to make two updates if you wanted to change the data, one to the columns with the data and then to the blob with the object in it. So, that makes no sense (thinking about it now).

Where it makes sense is probably where I was thinking of using it in the first place, in fact. I have an ERROR table which contains some error information, and I wanted to include all the user information I have in a column along with the error information so I can have a better idea about what caused the error. In that case, I don't need to update the blobs, I don't need to run queries on the blobs... I just need to extract the information associated with the error as is. So, that's probably a good situation for it.

So, I don't know... that seems like a clearer analysis? Unless there's something wrong with the above...


Assisted Solution

jagrut_patel earned 200 total points
ID: 36509636
Whether to persist User object into DB depends on how costly you think is it to re-create the same object again?

In both cases Database trip is still there. If we consider volume of data transferred between the two approaches then I believe serialized blob of User object would be larger.

If re-creation of User object is expensive then how about storing it into Cache. Thus you can put logic that retrieves ready-made object from Cache and if required User object is not cached create it and put into Cache.
LVL 76

Accepted Solution

slightwv (䄆 Netminder) earned 250 total points
ID: 36509923
My 2 cents:  

I would store it unserialized for many of the reasons you posted:  Ease of update and selectivity.

You also do not need to write a bunch of maintenance/migration code if the serialized object changes.

The 'R' in RDBMS is Relational.  If you are not going to take advantage of the power of a database, then why use one?  Let alone Oracle.  There are MUCH cheaper options at that point.

Author Comment

ID: 36510022
yeah thanks for that... i'll go with what i was going for initially then, just saving the object in a blob if all i want to do is store it and read it later as I do with the error table... in that situation it's quite useful...

thanks for input...


Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question