I am writing a LINQ query. But, i am getting null object reference error for Model.StudentSummary.StudentDetails.
I put breakpoint on following foreach and when i mouse over Model.StudentSummary.StudentDetails i see StudentDetails is null.
I have initialized the whole model class than why it didn't initialize List<StudentDetails> in StudentSummary class?
foreach (Summary summary in Model.summaryData)
{
Model.StudentSummary.StudentDetails.Add(new SafetyDetails
{
Name = summary.Name,
ManTimeWorked = summary.TotalTime,
});
}
Model.cs
public class Report : BaseReportModel
{
public Report()
{
StudentSummary = new StudentSummary();
}
public StudentSummary StudentSummary { get; set; }
}
public class StudentSummary
{
public string Name { get; set; }
public List<StudentDetails> StudentDetails { get; set; }
}