我正在尝试从数据库中获取最后100行并在datatable中显示它。但是我这样做了Argument.NullException
。我该如何解决这个问题?
视图模型
public class WalkInnVM
{
...
...
public class WalkInnDataTable
{
public string SlNo { get; set; }
public string Name { get; set; }
public string Center { get; set; }
public string Mobile { get; set; }
public string CareGiverMobileNo { get; set; }
public string Qualification { get; set; }
public string CourseRecommended { get; set; }
public int Id { get; set; }
}
}
控制器类
WalkInnVM.WalkInnDataTable _dTableWalkInn = new WalkInnVM.WalkInnDataTable();
if (_currentRole == (int)EnumClass.Role.SALESINDIVIDUAL)
{
_dTableWalkInn = _db.StudentWalkInns
.AsEnumerable()
.Where(x => x.ProspectHandledEmpID == Int32.Parse(Session["LoggedUserId"].ToString()))
.OrderByDescending(x => x.Id)
.Select(x => new WalkInnVM.WalkInnDataTable
{
SlNo = "",
Name = x.CandidateName,
Center = x.CenterCode.CentreCode,
Mobile = x.MobileNo,
CareGiverMobileNo = x.GuardianType == (int)EnumClass.CareGiver.Father ? "FATHER :" + x.GuardianContactNo :
x.GuardianType == (int)EnumClass.CareGiver.Guardian ? "GUARDIAN :" + x.GuardianContactNo :
x.GuardianType == (int)EnumClass.CareGiver.Mother ? "MOTHER :" + x.GuardianContactNo :
"SPOUSE :" + x.GuardianContactNo,
Qualification = x.QlfnMain.Name + "," + x.QlfnSub.Name,
CourseRecommended = x.StudentWalkInnCourses
.Select(c => c.Course.Name)
.Aggregate((m, n) => m + "," + n),
Id = x.Id
})
.Take(100);
}
此处Take(100)
显示ArgumentNullException
,使用var
变量而不是typos
时问题得以解决。