using System.Collections.Generic;
public static void Main()
List<ProjectResult> result = new List<ProjectResult> {
new ProjectResult { Name = "Project 1", MonthYear = "2020-08", LiveDate = Convert.ToDateTime("2020-08-28 00:00:00.000") },
new ProjectResult { Name = "Project 2", MonthYear = "2020-08", LiveDate = Convert.ToDateTime("2020-08-27 00:00:00.000") },
new ProjectResult { Name = "Project 3", MonthYear = "2020-08", LiveDate = Convert.ToDateTime("2020-08-26 00:00:00.000") },
new ProjectResult { Name = "Project 4", MonthYear = "2021-08", LiveDate = Convert.ToDateTime("2020-08-28 00:00:00.000") },
new ProjectResult { Name = "Project 5", MonthYear = "2021-08", LiveDate = Convert.ToDateTime("2020-08-27 00:00:00.000") },
new ProjectResult { Name = "Project 6", MonthYear = "2021-08", LiveDate = Convert.ToDateTime("2020-08-26 00:00:00.000") },
var queryAug = result.Where(c => c.LiveDate != Convert.ToDateTime("1900-01-01 00:00:00.000") && c.LiveDate.Month == 8)
.GroupBy(c => new { c.MonthYear, c.Name})
.Select(g => new DynamicProjectCalendarAug
MonthYear = g.Key.MonthYear,
ProjectName = g.Key.Name,
Aug = g.Where(c => c.LiveDate != Convert.ToDateTime("1900-01-01 00:00:00.000") && c.LiveDate.Month == 8).Max(c => c.Name)
var querySep = result.Where(c => c.LiveDate != Convert.ToDateTime("1900-01-01 00:00:00.000") && c.LiveDate.Month == 9)
.GroupBy(c => new { c.MonthYear, c.Name})
.Select(g => new DynamicProjectCalendarSep
MonthYear = g.Key.MonthYear,
ProjectName = g.Key.Name,
Sep = g.Where(c => c.LiveDate != Convert.ToDateTime("1900-01-01 00:00:00.000") && c.LiveDate.Month == 9).Max(c => c.Name)
List<object> query = queryAug.Cast<object>()
.Concat(querySep).ToList();
foreach(var item in queryAug)
Console.WriteLine("GroupRowId: {0}, MonthYear: {1}, ProjectName: {2}", item.GroupRowId, item.MonthYear, item.ProjectName);
public class ProjectResult
public string MonthYear { get; set; }
public string Name { get; set; }
public DateTime LiveDate { get; set; }
public class DynamicProjectCalendarAug
public int GroupRowId { get; set; }
public string MonthYear { get; set; }
public string ProjectName { get; set; }
public string Aug { get; set; }
public class DynamicProjectCalendarSep
public int GroupRowId { get; set; }
public string MonthYear { get; set; }
public string ProjectName { get; set; }
public string Sep { get; set; }