c# - how to insert data into db as a serialized object -
My basic question is how to insert data as a serialized object in DB and remove it and use it. .. any suggestion !!?
Example:
{id: 1, userId: 1, type: photo, time: 2008-10-15 12:00:00, data: {photoId: 2089, photoName: As you see how I can insert data in column data
and then use it !
Another question is if I add data inside
photoName
and get the name Instead of id
according to this table ( photos
) photoName
(right !?) Also I can not be able to create a relationship between the table photo and the current table - (id
= & Gt;
photoId) - If I store data like this I am .. So one part of the problem is that I do not know what kind of information is being stored in the column
data
so I do not customize a different column All these types of information ...
Usually I look here for two options.
-
You can store an XML serialized object in a database, and you can only use standard XML serialization, here it is that you can optimize for your needs. .
-
You can create a true table for this object, and you can work in the "standard" way.
With the option 1, filtering / joining / searching "data" columns in the information, although still technically possible, there is nothing that I would recommend and in my opinion static storage The procedure will not be more likely to be necessary for some backend queries like a user setting unit or some other object.
With option 2, yes, you have to do more work, but if you define an object well, it will be possible.
Explanation In relation to my example above # 1, you will write in the memory stream etc. for the serialization instead of a file.