I would like a method to return a Dictionary of Dictionary from an IQueryable formula. Typically,
Dictionary<int, Dictionary<DateTime, string>>
At first, I looked at ToDictionary() of course but couldn’t find a way to declare two one after the other.
Then, i loooked at ToLookup() and I have a way to carry this with a ILookup with the string being my secondary dictionary(the DateTime.Tostring() + the other string)… you follow ? 🙂
But I don’t find the ILookup solution really confortable (parsing a date to string and when i receive the data -> string to date.. beuark)
That would give something like that
return this.ttdc.Trackers.GroupBy(t => new { TrackerTaskId = t.TrackerTaskID, DateGenerated = t.TrackerDateGenerated })
.Select(t => new { taskId = t.Key.TrackerTaskId, DateGenerated = t.Key.DateGenerated, count = t.Count() })
.ToLookup(k => k.taskId.Value, k => k.DateGenerated.Value.ToString() + "|" + k.count);
Now, i’m thinking about creating a List of self created class with the 3 informations I need as properties.
Could you help me chosing the best pattern ? This method is hosted on a windows service and I would like to limit the amount of data transfered to the client.
Thank you
Here’s an example, using
GroupByandToDictionary: