Tuesday, April 22, 2014

LINQ Case statement within Count asp net c#

var statu = from x in dc.Attendance
            group x by 1 into g
            select new
            {
                ID = g.Key,
                Presents = g.Where(t => t.AttendanceStatus == "Present").Count(),
                Absents = g.Where(t => t.AttendanceStatus == "Absent").Count(),
                Leaves = g.Where(t => t.AttendanceStatus == "Leave").Count(),
            };