views:

31

answers:

2

My application contains a set of model classes. e.g. Person, Department...

The user changes values for instances of these classes in the UI and the classes are persisted to my "project" file. Next time the user can open and edit the project.

Next version of my product may change the model classes drastically. It will still need to open existing projects files (I will know how to handle missing data).

How is it best to persist my model classes to the project file?

The easiest way to persist classes is Data contract serialization. However it will fail on breaking changes (I expect to have such). How to handle this?

  • use some other persistence, e.g. name-value collection or db which is more tolerance
  • ship a "project converter" application to migrate old projects. This requires to either ship with both old and new models or to manipulate xml, which is best?
A: 

I would recommend including a version number in your project file schema. Then provide XSLT to convert between different versions of the project schema. When a file is opened, first open as XML and check the version. If it's not the latest version, up-convert it, then process as normal.

Toby
I have a very complex classes hierarchy. Also I use netDataContract serialziation which makes the xml even uglier. How easy would it be to build the xslt? Are there any tools for that? Isn't is easier to use a dictionary, which will never break anything?
Yaron Naveh
Toby
A: 

Since in future you need to support all "project" files created by your current application. In my view an application to migrate your current data to new format is a better solution. This approach would keep the new code clean for reading and writing new data format. So the logic will not be cluttered with something like , if old format do that, if new format do that. Also, the migration application will be independent and can be tested easily for any issues related to incorrect data transformation.

prasrob