English 中文(简体)
Save/Load Properties to file or database provider
原标题:

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 ?

最佳回答

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.

问题回答

.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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签