views:

47

answers:

3

I need to save and load properties of a Class dynamicly, but what is the best practis for this ?

I have for now, two classes that I need to save.

public abstract class BaseComponent {

   protected int ComponentID { get; set; }
   protected string ComponentName { get; set; }
   protected Dictionary GetAllProperties{) { /* Reflection */ }

}


public class Article : BaseComponent {

   protected string Title { get; set; }
   protected string Content { get; set; }

}

Here I'm thinking to table:

Table: Component, ComponentID, Parrent -> and more Table: ComponentProperties: ComponentID, Key, Value -> and more

I need to use as must of the dotNet framework, but still keep it simpel. Im think og use a Provider, I need the function og make different data provider:thatcan save to xml file, sql database or oracle database, you name it.

Do I use a provider, or somethnig else ?

A: 

The answer for your persistence will depend very much on the scale of what you're writing. Storing XML in files or a database certainly works, as does a metadata driven generic schema (as you described), but making them work for large scale data can be problematic. Salesforce.com did a recent presentation on how they handle dynamic entities in a multi-tenant architecture (see here), but I doubt you need anything of that scale.

My recommendation would be to store as XML to start. The key issues to solve with the generic schema are joins between logical entities and the trouble of pulling together data that belongs to a single entity when it's split out into key/value pairs in a table.

Bernard Chen
Jeg tror jeg vil bruge DAL - Data Access LayerOg til det, har jeg lavet et Interface.Denne artikel har givet mig lidt inspiration: http://www.codeproject.com/KB/dotnet/Independent_DAL.aspx
Dennis Larsen
In eng: I think I will use DAL - Data Access Layer And to that I have made an interface. This article has given me some inspiration.
Dennis Larsen
A: 

.Net Framework 2.0 or later has a great class that helps you to implement this task, called SettingsBase. You can find it in System.Configuration assembly. You have to create a class for instance BaseComponentSettings and derive it from System.Configuration.SettingsBase. SettingsBase is provider model and you can support many data source as well.

Mehdi Golchin
A: 

How do I set the Question to answered. I have set the (right-mark) ?

Dennis Larsen