C# Linq Query - Groupby -
i have datatable holds data such:
date operationa operationb operationc today 5 today 6 today 7
now, want like:
date operationa operationb operationc today 5 6 7
i've had @ linq group clause, seems seperate data being grouped , doesn't keep within collection - althought linq novice, may missing something.
could please advise.
thanks.
class operation { public datetime date { get; set; } public int operationa { get; set; } public int operationb { get; set; } public int operationc { get; set; } } var operations = loaddata(); var result = operations.groupby(o => o.date) .select(g => new operation { date = g.key, operationa = g.sum(o => o.operationa), operationb = g.sum(o => o.operationb), operationc = g.sum(o => o.operationc) });
p.s: db design looks weird. think table should this:
date operation type 2010-1-1 5 2010-1-1 6 b 2010-1-1 7 c
Comments
Post a Comment