3

I often write my objects out to a database in xml form.

However, if I change the form of my objects, say by changing the name or by changing the fields, I can no longer read them from the database, which makes somewhat difficult the task of reading them, converting them to their new form, and writing them back out to the database.

I'd rather not have to rename my classes everytime I change something about them.

*Note: I am relying on C#'s XmlSerialization/Deserialization of objects for generating the Xml. Perhaps this is not desirable if I change the format of the objects.

user420667
  • 6,552
  • 15
  • 51
  • 83
  • If you are doing that lots, you might want to look at a document db; better suited to that type of use than a RDBMS is... – Marc Gravell Feb 17 '11 at 17:55

2 Answers2

2

If you implement the ISerializable interface on your objects, then you can implement custom serialization/deserialization routines that provide backwards compatibility with older versions of the objects.

See here for an example of how it can be done: ISerializable and backward compatibility

Community
  • 1
  • 1
Sean U
  • 6,730
  • 1
  • 24
  • 43
1

It ultimately depends on how you serialize your objects.

One convenient option is to store them as hash (key-value pairs). This way, if to class Dog having property name I add another property breed, existing objects won't be invalidated. They'll just have have breed = nil.
Exact storage format (xml, json or separate 'properties' table) is not important in this case, the important thing is how you convert objects to it and back.

But I don't think anyone could give specific suggestions without knowing specific platform.

Nikita Rybak
  • 67,365
  • 22
  • 157
  • 181