您好我可以从WCF(API)获取结果到数据表并绑定到网格像:
DataTable dt
EventStart | EventEnd
=============================================
1/9/2015 1:00:00 Pm | 1/9/2015 1:15:00 Pm
1/9/2015 3:00:00 Pm | 1/9/2015 4:15:00 Pm
13/10/2015 10:00:00 Am | 13/10/2015 11:15:00 Am
13/10/2015 1:00:00 Pm | 13/10/2015 2:15:00 Pm
但是我希望Result在另一个DataTable dt2中像这样
Date | Total Minutes
==============================================
1/9/2015 | 150 Minutes
13/10/2015 | 150 Minutes
任何人都可以帮助......我是LINQ的新手......
答案 0 :(得分:1)
跳过数据表,直接绑定到LINQ结果,如下所示:
Grid.DataSource=result
.GroupBy(x=>x.EventStart.Date,x=>(x.EventEnd-x.EventStart).TotalMinutes)
.Select(x=>new {Date=x.Key,TotalMinutes=x.Sum()});
这假设WCF返回IEnumerable,具有EventStart和EventEnd(如数组,List,IList,Collection等)