_AttendedDays = new AttendanceBAL()
.GetAttendanceListOf(q._RollNumber)
.Where(date => date != null)
.Select(date => new DateTime(date._Date.Year, date._Date.Month, date._Date.Day))
.Distinct()
.ToList(),
The problem is with running Where()
on null instance. Possible solutions:
1) modify GetAttendanceListOf
to return an empty list if no attendance (good idea in general, as null object pattern is very often a life saver, and for collection, an empty collection is often semantically similar to null)
2) if you don't control that method, write a safe extension method which will return empty list in case of null, e.g.
List<AttendanceType> SafeAttendanceList(this AttendanceBALType bal, RollNumber rn)
{
return bal.GetAttendanceListOf(rn) ?? new List<AttendanceType>();
}
Then call it as:
_AttendedDays = new AttendanceBAL()
.SafeAttendanceListOf(q._RollNumber)
.Where(date => date != null)