recordsList.ListOfRecords = new StudentRecordsBAL()
.GetStudentsList()
.Select(q => new StudentRecords()
{
_RollNumber = q._RollNumber,
_Class = q._Class,
_Name = q._Name,
_Address = q._Address,
_City = q._City,
_State = q._State,
_Subjects = q._Subject,
_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(),
_AttendedSubjects = GetAttendedSubjects(q._RollNumber)
}).ToList();
上面代码中的方法GetAttendanceListOf(q._RollNumber)
将返回数据库中的记录列表,如果传递的“roll-no”没有记录,则返回“null”。一个 linq 查询将被终止生成错误
“值不能为空”。
有没有办法处理这个错误并使 LINQ 跳转到下一步?