I have a LINQ statement below which should return 110 records back to my view. When I checked SQL Server, my table has records in it, but when I try to retrieve those records based on an Id and do @foreach(var item in Model)
its causing a null reference error. Any help would be appreciated.
LINQPAD --Returns 110 records (RPT is the schema)
RPT.Team_History.OrderByDescending (r => r.DateOfAction).Where(r => r.MgrID ==212)
Controller Code (DB First approach used. RPT schema dropped when VS generated models)
public PartialViewResult _TeamTransitionDisplay()
{
var mgrID = 212;
IEnumerable<TeamHistoryViewModel> teamHistory;
teamHistory = db.Team_History
.Where(x => x.MgrID == @mgrID)
.Select(x => new TeamHistoryViewModel
{
DateOfAction = x.ActionDate,
DeptID = x.DeptID,
Operation = x.Operation,
StartDate = x.StartDate,
AStartDate = x.AStartDate,
FStartDate = x.FStartDate
}).ToList();
return PartialView("_TeamDisplay", teamHistory);
}
[NullReferenceException: Object reference not set to an instance of an object.]
Advice would be appreciated.