linq,multiple,field,group,by

Mark 7/27/2016 0

this code will group linq query for multiple fields

C#
 using (var db = new WeblogContext())
 {
   return (from t in db.PageVisits.Where(p => p.DayId == dayId)
                        group t by new { t.PageId, t.PageName }
                            into grp
                            select new DailyVisit
                            {
                                PageId = grp.Key.PageId,
                                PageName = grp.Key.PageName,
                                Visits = grp.Sum(t => t.VisitCount)
                            }).ToList();

 }
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments