简体   繁体   中英

How to persist Display properties associated to C# Class properties in database?

So here is the current problem I'm facing:

  1. I have C# Business Object classes that are generated dynamically from XML Schema.

  2. I build forms dynamically to display and capture data bound to my Business Objects.

  3. I store my serialized (xml) objects into the database.

  4. I need to persist the display properties associated to each Property in my Business Object C# classes (How to accomplish this??)

Lets say I have a Person Business Object:

public class Person
{
   public string Name {get;set;}
   public PhoneType Phone {get;set;}
}

public class PhoneType
{
   public string HomePhone{get;set;}
   public string WorkPhone{get;set;}
}

Now let's say I create a new Person:

Person me = new Person();
me.Name = "BOB";
me.Phone = new PhoneType()
me.Phone.HomePhone = "1234";
me.Phone.WorkPhone = "4321";

Now when I build my form I know that Person.Name is a TextBox of Width = 300 and Height = 30 and my PhoneType.HomePhone and PhoneType.WorkPhone are TextBoxes of Width 200 and Height = 30.

What are the best ways to persist those Display Properties in the DataBase and associate them to each of the Properties in my Business Objects? Considering that most of my Business Objects are represented by very deep object graphs... so I'm wondering what the best way is to recursively store and regenerate display properties from Database based on the deep hierarchical nature of my model.

Now a few conditions: -I don't want to store static forms since my application is very dynamic. XSD -> Code -> Form -Display properties may be user-specific (eg backcolor of certain field), so can't just have generic form templates -I just need a good mechanism to associate POCO properties to display properties so I can build my forms on the fly and persist changes to the database

I'm currently exploring the possibility of creating a PropertyBag (collection) property in each of my Business Objects and populate them recursively as I navigate the object graph, but haven't gone far yet..

The way that we handle this is to provide unique identifier attributes to each of the classes, then store the UI definition, including required fields, size, label values, etc, in the database.

We actually also attribute each of the properties in the classes in order to separate those that are visually important from those that are "helpers" only.

At run time, we use reflection to retrieve the attributes for the classes and properties that are to be displayed, then fetch the appropriate list of visual modifiers from the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM