【发布时间】:2015-10-23 03:58:17
【问题描述】:
我正在使用此代码按年、月和employeeId 对行进行分组。
var dtrSummary = from dtr in db.DTRs
group dtr by new { dtr.Date.Year, dtr.Date.Month, dtr.EmployeeId } into g
select new
{
Year = g.Key.Year,
Month = g.Key.Month,
NoOfDays = g.Count(),
FullName = db.EmployeeRates.Where(e => e.Id == g.Key.EmployeeId).Select(e => e.FullName).FirstOrDefault(),
Time1 = // Get total hours between two datetime
// DateTime timein = new DateTime(year, month, day, tihh1, timm1, 0);
// DateTime timeout = new DateTime(year, month, day, tohh1, tomm1, 0);
// Timespan totalTime1 = timeout - timein;
};
但我不知道如何使用 linq group by 来获取总小时数,就像您在上面看到的那样。
这是我的桌子:
+----------------------------------------------------------------------+
| Date | Timeinhh | Timeinmm | Timeouthh | Timeoutmm | EmployeeId |
+----------------------------------------------------------------------+
| 10/1/2015 | 9 | 0 | 18 | 0 | 1 |
| 10/2/2015 | 9 | 0 | 18 | 0 | 2 |
| 10/3/2015 | 9 | 0 | 18 | 0 | 1 |
| 10/4/2015 | 9 | 0 | 18 | 0 | 2 |
+----------------------------------------------------------------------+
【问题讨论】:
标签: linq