Possible Duplicate:
linq-to-sql group by with count and custom object model
I have a linq-to-sql query that groups and counts and the result ends up in a dictionary. I want to map the dictionary to an object model’s property. The object model looks like this:
public class MyCountModel()
{
int CountSomeByte1 { get; set; }
int CountSomeByte2 { get; set; }
int CountSomeByte3 { get; set; }
int CountSomeByte4 { get; set; }
int CountSomeByte5 { get; set; }
int CountSomeByte6 { get; set; }
}
I want to map the dictionary so that the query ends like this:
var TheQuery = MyDC.SomeTable
.Where(...)
.GroupBy(...)
.ToDictionary(x => x.Key, x=> x.Count()
.Select(m => new MyCountModel()
{
CountSomeByte1 = ..., // the value where Key is 1
CountSomeByte2 = ...., // the value where Key is 2
....
CountSomeByte6 = .... // the value where Key is 6
});
How could I write something like this?
Thanks for your suggestions.
You don’t want to select anything. I think you simply want to ‘reduce’ the query to a single value: