locked
What Approach to take? RRS feed

  • Question

  • I have a normalized forecast database where the timeline is in one field called ForecastTimeline.  However, in the application the users want to edit the entity by having the timeline pivoted as column headers so the timeline is across the top.  

    I am curious to what approach i should take to achieve this, obviously the entity framework does not handle this.  
    Friday, January 22, 2010 4:56 PM

Answers

  • DataTables could work nicely here, and you can just write some code to project out your entities into the DataTable shape that you need. When you want to save the data, you can copy it back from the datatable to the entity.

    I suspect a generalized mechanism for this would be easy to write, e.g., very roughly something like:

    public DataTable EntityListToDataTable(IEnumerable<T> Entities, Func<T, ColumnValue> columnValue, Func<T, RowValue> rowValue)
    {
    ...
     foreach(T Entity in Entities) {
       table.Columns.Add(new DataColumn(columnValue(Entity), typeof(rowValue(Entity));
    ...
     }
    ...
    }

    Which would allow you to write:
    var myBindingDataTable(myContext.ForecastTimeLine, timeLine => timeLine.Time, timeLine => timeLine.Value);

    You could also write a CopyDataTableValuesToEntities method in a similar way as well.

    HTH
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, January 22, 2010 5:54 PM