Approach to using database

Jul 10, 2014 at 9:35 AM
I had a question about the general approach to using the database, as how I expected to use it is becoming very problematic for the following reason.

I have a collection of classes with their own members (some values, some lists and some other classes) which get stored in the database. I found that if I tried to update one of the values in the classes belonging to the objects in the database (i.e. a 'child' class of an object saved in the database), the main object was being duplicated - i.e. I was ending up with 2 of the 'parent' class in the database, one with values before the changes to the child class and one after.

I got around this by deleting the original object in its entirety and then storing the modified version. Once I understood about cascading delete, this seemed to be working ok - and the number of objects in the database was correct. However, I've now learned that the deleted objects are not removed from the file, and I need to use the DefragmentTo function to get the database size to equal the objects that are still needed.

This causes me a big problem as there are regularly very small changes to child-classes that are part of much bigger objects. As the deleted 'parent' objects are not really removed from the database, it gets very big very quickly. Whilst defragging is a solution, performing a defrag every time someone makes one of the very regular changes would be ridiculous, especially once the database file has become larger in size.

I get the feeling I'm not using the database in the way it was intended, otherwise I don't think I would have these problems. My question therefore is this: how should I be handling making changes to the values of 'child' classes within a larger 'parent' class that is stored in the database so I don't have to replace the entire 'parent' class every time.

Any help would be hugely appreciated.
Aug 10, 2014 at 8:39 AM
All about that is done for couple of reasons (marking instead of deleting):
  • performance, operation on file disk are expensive
  • complexity, existing solution is quite simple and allows on easy implementation of many NDatabase features. Changing that will cause to rise complexity and will make impact on existing features, which will made NDatabase less stable and more complex.
I'm happy to see any proposed solution to make it working, which will not harm much other features which are already supported by NDatabase.