I am fairly new to MVC and EF, and what I am trying to show the data from my database to my view. This is my action:
public ActionResult MalfunctionsList(MalfunctionDTO malfunctionDTO)
{
var malfunctions = _context.Malfunctions.ToList();
var customer = _context.Malfunctions.Single(c => c.Id == malfunctionDTO.CustomerId);
var movie = _context.Malfunctions.Where(m => malfunctionDTO.MovieIds.Contains(m.Id)).ToList();
return View(malfunctions);
}
When code runs I get System.InvalidOperationException: Sequence contains no elements in this line:
var customer = _context.Malfunctions.Single(c => c.Id == malfunctionDTO.CustomerId);
This is my DTO:
public class MalfunctionDTO
{
public int CustomerId { get; set; }
public List<int> MovieIds { get; set; }
public Customer Customer { get; set; }
public Movie Movie { get; set; }
public string ReportDescription { get; set; }
}
In my table in the database the customerId isn't empty.