'Using lambda expression to pass multiple values with aggregate functions to view in MVC (For nested tables)

I have to Tables named Tasks and TaskDetails, I'm currently working on a todo list web application using MVC 5.

I created a query to retrieve the rows from the two tables based on an employee ID as shown below

SELECT T.TaskID,T.Title,T.Status AS TaskStatus,T.EmpID,TD.SID,TD.ToDo,TD.EndDate,TD.EndTime,TD.Priority,TD.Status AS TDStatus
FROM TASKS T 
INNER JOIN TaskDetails TD ON T.TaskID=TD.TaskID
WHERE T.EmpID='12345' ORDER BY SID DESC

enter image description here

In my Controller, I'm using the following code to pass the data to the View .

//Controller

public ActionResult MyToDoLists()
{
List<ToDoListsVM> todoLists = this.LoadPrivateData();
var booksGrouped = from b in todoLists
group b by new { b.TaskID,b.Title } into g
select new Group<int,string, ToDoListsVM> { Key = g.Key.TaskID,Title=g.Key.Title, Values = g };
ViewBag.ToDoLists = booksGrouped.ToList();           
return View();
}

Lambda class

public class Group<K,K1, T>
{
    public K Key;
    public K1 Title;
    public IEnumerable<T> Values;
}

In the view, the ToDos are grouped per each TaskID and TaskName, and the fields marked in green are retrieved based on the lambda expression as shown below

enter image description here

But my issue now, is that I cannot get the values for ToDos and Completed fields, as marked in RED. Note: ToDos shows the total of todo list per each task Completed: shows the completed todos per each task



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source