如何在Linq查询行中创建列?

时间:2017-01-20 11:38:01

标签: c# linq

我有一个包含如下行

的表格
Month - Agent   - ResolveCount  
1     - John    - 14    
1     - John    - 12           
2     - Smith   - 64              
2     - Smith   - 23         

我的模特:

public int Month { get; set; }
public Agent Agent { get; set; }
public int ResolveCount { get; set; }

我的Linq查询

   List<ResolveMonthlyAgentReport> _result =
        (from t in ConversationCollection.AsQueryable<Conversation>().AsEnumerable()
        where t.CompanyId == _companyId && t.CreateDate.Year == _year && t.ResolvedDate != null && t.ResolvedAgentId != null
            group t by new { t.CreateDate.Month, t.ResolvedAgentId }
            into grp
            orderby grp.Key.Month
            select new ResolveMonthlyAgentReport
            {
            Agent = _agentList.Where(p => p.AgentId.ToString() == grp.Key.ResolvedAgentId).FirstOrDefault(),
            Month = grp.Key.Month,
            ResolveCount = grp.Count(t => t.ResolvedAgentId == grp.Key.ResolvedAgentId) 
            })
        .Where(p => p.Agent != null)
        .ToList();

结果:

Month - Agent   - ResolveCount  
1     - John    - 14    
1     - John    - 12           
2     - Smith   - 64              
2     - Smith   - 23    

这是我想要的结果:

Agent    - 1.month - 2.month - x.month
John     - 14      - 12
Smith    - 64      - 23

我的linq查询应该如何?

0 个答案:

没有答案