最近剛好有使用到Pivot語法
我是參考這個網站
http://jengting.blogspot.com/2018/05/LINQ-Pivot.html
參考他的做法大致上已經實現,目前還有個問題
假設我想再追加一個欄位是用來計算請假的次數
像AAAA的總時數就是54
BBBB則是36
請問這個我該如何實現呢?
var result = Data.GroupBy(g => g.Employee)
.Select(g => new
{
Employee = g.Key,
Personal = g.Where(w => w.Kind == "事假").Sum(s => s.Hours),
Sick = g.Where(w => w.Kind == "事假").Sum(s => s.Hours),
Company = g.Where(w => w.Kind == "公假").Sum(s => s.Hours),
Paternity = g.Where(w => w.Kind == "陪產假").Sum(s => s.Hours),
//總時數
ToltalHours = g.Sum(s => s.Hours),
//總次數
TotalTimes = g.Count()
});