c# - Group by for list in list -
i have list of issues : list<issue> issue class :
public class issue : baseentity { private string m_keystring; [jsonproperty("expand")] public string expand { get; set; } [jsonproperty("id")] public int id { get; set; } #region special key solution [jsonproperty("key")] public string proxykey { { return key.tostring(); } set { m_keystring = value; } } [jsonignore] public issuekey key { { return issuekey.parse(m_keystring); } } #endregion special key solution [jsonproperty("fields")] public fields fields { get; set; } } class fields looks :
public class fields { [jsonproperty("summary")] public string summary { get; set; } [jsonproperty("assignee")] public assignee assignee { get; set; } [jsonproperty("worklog")] public list<worklog> worklogs { get; set; } } and class worklog:
public class worklog : baseentity { [jsonproperty("updateauthor")] public string author { get; set; } [jsonproperty("timespent")] public string timespent { get; set; } [jsonproperty("timespentseconds")] public int timespentseconds { get; set; } } i want on output author - sum (timespentseconds)
so need group author , sum.
for each item in issues list make :
var sumtime = issue.fields.worklogs.groupby(x => x.author).select(x => new { user = x.key.name, amount = x.sum(s => s.timespentseconds) }); which group user , count sum.
but how can manage same not 1 item in list list?
ok, think you're saying can run query single issue, want able run on items in list<issue>.
i'm assuming don't want break out separately issue, i'd this:
list<issue> issues = // issues wherever var sumtime = issues.selectmany(issue => issue.fields.worklogs) .groupby(x => x.author) .select( x => new { x.key.name, amount = x.sum(s => s.timespentseconds) } ); disclaimer:
this done entirely memory, no testing.
Comments
Post a Comment