I think I need a way to perform a pivot or crosstab using C# and Linq with an indeterminate number of columns. However, I will add some beginning detail to see where it goes.
< Beginning detail >
Imagine a table that has two fields:
string EventName;
Datetime WhenItHappend;
We want to generate a report like the example below where we group by the EventName, then have a series of columns that calculate some date and time frame count. The difficulty is obviously a variable number of columns.
Sport Jan 2010Jan 2009Feb 2010Feb 2009
Basketball 26 18 23 16
Hockey 28 19 25 18
Swimming 52 45 48 43
The customer can create any number of named event counters for a report. The functions are always the same: "Name", "begin", "end".
Any way to assemble this as a single linq IQueryable result in C#?
< End Beginning detail >
As far as SQL goes, I tried creating a date range table {TimeFrameName, begin, end} and joined that to the above table where begin <= whenItHappened and whenItHappened <= end, which produced a nice set of {EventName, TimeFrameName} then did a count(*), but was still left with how to transform the data, making the rows in to columns.