With .Net MVC i am using DB First approach. I need a School Day Program, but I am not sure to use pivoting, DataTable or anything else?
The table in SQL is like that:
WeeklyProgram
Id RoomId Hour Day
1  1      9    1
2  1      12   1
3  2      14   1
4  2      12   2
5  3      11   1
6  4      10   2
And trying to convert it to a table in html with null cells like this:
For Day 1 My School Program is;
#     Room1 Room2 Room3
9:00  1     null  null
10:00 null  null  null
11:00 null  null  5
12:00 2     null  null
13:00 null  null  null
14:00 null  3     null
Tried pivoting but cant get what i thought.
Thanks all.
UPDATE: I'VE FOUND AN ANSWER
if (!date.HasValue)
            date = DateTime.Now;
        List<WeeklyProgram> modelBase = table
            .Where(b => b.Day == day)
            .ToList();
        int[] hours = { 9, 10, 11, 12, 13, 14};
        List<PivotTable> pivotTable = new List<PivotTable>();
        foreach (var hour in hours)
        {
            PivotTable pivotRow = new PivotTable() { Hour = hour };
            foreach (var item in modelBase)
                if (item.Hour == hour)
                    switch (item.RoomId)
                    {
                        case 1:
                            pivotRow.Room1 = item.Id;
                            break;
                        case 2:
                            pivotRow.Room2 = item.Id;
                            break;
                        case 3:
                            pivotRow.Room3 = item.Id;
                            break;
                    }
            pivotTable.Add(pivotRow);
        }
        return pivotTable;
--
    public class PivotTable
{
    public int Hour { get; set; }
    public int Room1 { get; set; }
    public int Room2 { get; set; }
    public int Room3 { get; set; }
    public int Room4 { get; set; }
    public int Room5 { get; set; }
}
 
    