locked
Object with extensible number of properties. RRS feed

  • Question

  • User966117239 posted

    I have a requirement where admins can configure an arbitrary number of extra columns of data for a user to enter when saving an entity - say an order.  The column definitions are system-wide, but are not known ahead of time, and the admins can create new ones at any time.  Does anyone have any ideas on how to handle this with a Dynamic Data site?  I'm using .NET and Entity Framework 4.0. 

    I would have an Order object with properties for ID, OrderType, Description, CreateDate, LastUpdated.  The definitions for the extensible additional columns are stored in a OrderInfoColumn table. I have the OrderInfoColumn entities working with Dynamic Data and the admin can CRUD them already.  The question is what's the best way to store & CRUD the values for the extensible OrderInfoColumns for each Order. 

    I was thinking of:

    Approach 1.  Add an XML column called OrderInfovalue to the Order entity.  This would have the column name\value pairs.
    Approach 2.  Store the values for each Order entity vertically:  Create a OrderInfoValues table with OrderID, OrderInfoColumnID and Value columns.

    With approach #1, I would create a new FieldTemplate for OrderInfoValues which takes the xml and parses\displays these in a GridView.  Probably via making a DataSet, then writing back XML to OrderInfoValues on update.
    With approach #2, I would have the OrderInfoValues be scaffolded as standard child objects.

    The downside to #1 is for each Order row in the list view, there would be a single OrderInfoValues column, and each row would have its own GridView (with its own set of column headers) within it.

    The downside to #2 is that to add values for each configured OrderInfoColumn, the user would have to click Insert New, select the right Order from a FK drop-down, select the OrderInfoColumn and enter the value, then save.  Then repeat.  Not very data entry friendly if you have even a decent amount of extra columns.  Plus, very easy to forget to add a value for a column or 2, and not the best for display (no extra OrderInfoColumn values seen in the Order list).

    I was also thinking of a 1a approach where in the Order list view, I dynamically add columns (one for each OrderInfoColumn), and bind to the OrderInfoValues, pull the right value from the XML for the specific column, and display that.  But, I got a little lost trying to do that, and handle editing, updating.  

    Has anyone done anything similar to any of these approaches with any success - or used a better approach?

    Thanks in advance,
    Keith

    Friday, June 3, 2011 4:45 AM

Answers

  • User966117239 posted

    Thanks Stephen, that was the way I was leaning after a night's sleep... Cool.  But good to have some confirmation.  And thanks for all your articles on C# bits - they've been quite helpful as I started with DD this week.

    I ended up creating a FieldTemplate for XmlAttribute.  Then in my custom ListDetails page for the object, I dynamically add DynamicField for each custom DataColumn that all have the XmlValues property as their DataField, and the DataFormatString as the column name.  Then the XmlAttribute template extracts the value from the XML for that column name.

    There is some other trickery, esp. getting around the fact that multiple templates are bound to the same object property on Edit - had to get fancy with the OldValues\NewValues dictionary and row changing events. 

    I wrote up a whole thing on it to post the code here, but don't see a way to add an attachment here.  So, I put it on my SkyDrive for anyone who's interested: http://cid-f78d6a9c9091b018.office.live.com/embedicon.aspx/Public/DDSample.zip 

    There's a ReadMe.txt that explains things.

    More work could be done for sure, but it gets me what I need for right now.  Let me know if anyone likes it or has questions, etc.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 7:48 PM

All replies

  • User-330204900 posted

    Hi Keith, I have thought of this using you option 1. but have never gon any futher with it due to issues with UI layout. But with DD on .Net 4 and Entity Templates you could surly do somthing using a custom entity template that added the extra columns and did the data binding it's self.

    Friday, June 3, 2011 5:07 AM
  • User966117239 posted

    Thanks Stephen, that was the way I was leaning after a night's sleep... Cool.  But good to have some confirmation.  And thanks for all your articles on C# bits - they've been quite helpful as I started with DD this week.

    I ended up creating a FieldTemplate for XmlAttribute.  Then in my custom ListDetails page for the object, I dynamically add DynamicField for each custom DataColumn that all have the XmlValues property as their DataField, and the DataFormatString as the column name.  Then the XmlAttribute template extracts the value from the XML for that column name.

    There is some other trickery, esp. getting around the fact that multiple templates are bound to the same object property on Edit - had to get fancy with the OldValues\NewValues dictionary and row changing events. 

    I wrote up a whole thing on it to post the code here, but don't see a way to add an attachment here.  So, I put it on my SkyDrive for anyone who's interested: http://cid-f78d6a9c9091b018.office.live.com/embedicon.aspx/Public/DDSample.zip 

    There's a ReadMe.txt that explains things.

    More work could be done for sure, but it gets me what I need for right now.  Let me know if anyone likes it or has questions, etc.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 7:48 PM
  • User-330204900 posted

    I will look at this sort of thing for a future custom Entity Template.

    Saturday, June 4, 2011 7:18 AM