Saving an Ad Hoc Model to a Table
We have a requirement whereby the user can define a brand new data entry form and associate that form to a document.
The new model will then be re-used and associated to many documents so it's not a use once model.
So clearly we can't code it in everytime there is a new form, and we can't create a new table everytime there is a new model.
This won't happen (every) day. In fact I think it's safe to say it's the exception to the rule.
However, we still need to cater开发者_如何转开发 for it, save the data to a table and represent the data and data entry on screen.
I thought about simply serialising the model into a table and the data into another table.
Has anyone actually done this and would you be willing to share your solution?
edit
This will be a WPF solution and not a web based one.
The obvious solution for me is using XML - this is the perfect tool for this scenario.
- User can define the form using some UI tool that you'll write.
- You parse that entry to generate some structured XML (or an XSD); you will determine
- Field names,
- Data types,
- Allowed nested values / references to other data
- Enum / 'drop-down' values etc
From there it's a matter of storing the definition file & using it.
- The XML document is stored in your database with a version, date, or user identifier
- The code that renders the data entry form will retrieve the appropriate XML document (the most recent?) from your database
- The form is dynamically generated (field names, data types etc are known)
- Any data that is entered into that dynamically generated form will validate against your structured XML.
- All data entry instances will be stored with a reference to that XSD document.
This ensures that you are able to correctly identify each 'data entry instance' (collect of values) against its relevant 'data entry form' (form definition XML)
The benefit of XML in this instance is that it's extensible - you can store any variation to the form in a consistent & compliant format - and it's very simple to dynamically generate a data entry form based on some XML instructions.
精彩评论