//filter the employee based on the office id, or you can join the Employee table and Office table and select the employee. var emplist = _dbcontext.Employees.where(c=>c.offid == offid ).ToList() //filter the employees report. var queryresult = (from emp in emplist from t in daysOfMonth select new EmployeeTemp() { Empid = emp.aid, Name = emp.empname, officename = _dbcontext.Office.where(o=> o.id == emp.offid).Select(o=>o).FirstOrDefault(), //find the office name Date = t.Date, ... }).ToList(); var result = queryresult.GroupBy(c => c.Name).Select(g => { var empvm = new EmployeeViewModel(); empvm.Name = g.Key; empvm.OfficeName = g.FirstOrDefault().officename; empvm.Attendance = new Dictionary(); foreach (var i in g) empvm.Attendance.Add(i.Date, i.Status); return empvm; }).ToList();