Grouping and joining in LINQ
foreach(var line in data.GroupBy(info => info.metric)
.Select(group => new {
Metric = group.Key,
Count = group.Count()
})
.OrderBy(x => x.Metric)
select FunctionalityId, IsActive, count(1) from CustomerFunctionalitySettings group by FunctionalityId, IsActive order by 1, 2
dept needOn status foo 5/1/2011 closed foo 5/1/2011 closed foo 5/1/2011 open foo 5/1/2011 open
Output Required
dept needOn status count foo 5/1/2011 closed 4 foo 5/1/2011 open 2
Solution:var query3 = from q3 in query2 group q3 by new { q3.Dept, q3.NeedOnWeek, q3.Status } into g select new { dept = g.Key.Dept, needOnWeek = g.Key.NeedOnWeek, status = g.Key.Status, count = g.Count() };
LEFT JOIN
var query = from p in db.Employees join r in db.Students on p.EmpId equals r.PersonId into temp from t in temp.DefaultIfEmpty() select new { Designation = p.EmpDesignation, EmployeeName = p.EmpName, FirstName = t.FirstName, LastName = t.LastName, Age = t.Age };
Comments
Post a Comment