我有一种方法,当我使用select子句时,(艺术家和流派)会抛出空引用异常。如果我不使用select子句,那么它就无法将 system.collections.generic.list转换为system.collections.generic.ienumerable 。
public ActionResult Attending()
{
var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
var gigs = _context.Attendances.Include(a => a.Gig.Artist).Include(a => a.Gig.Genre).Where(a => a.AttendeeId == userId).ToList();
var viewModel = new GigsViewModel()
{
UpcomingGigs = gigs,
ShowActions = User.Identity.IsAuthenticated,
Heading = "Gigs I'm Attending"
};
return View("Gigs", viewModel);
}
这是我的ViewModel:
public class GigsViewModel
{
public IEnumerable<Gig> UpcomingGigs { get; set; }
public bool ShowActions { get; set; }
public string Heading { get; set; }
}
这是我的出勤班
public class Attendance
{
public Gig Gig { get; set; }
public ApplicationUser Attendee { get; set; }
[Key]
public int GigId { get; set; }
[Key]
public string AttendeeId { get; set; }
}