I'm trying to query the following entities in my application:
public class Reservation
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ReservationId { get; set; }
public int PersonId { get; set; }
[ForeignKey("PersonId")]
public Person Person { get; set; }
[ForeignKey("FilmShowId")]
public FilmShow FilmShow { get; set; }
public int FilmShowId { get; set; }
}
public class Person
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int PersonId { get; set; }
[Required]
[MaxLength(255)]
public string FirstName { get; set; }
[Required]
[MaxLength(255)]
public string LastName { get; set; }
public string Email { get; set; }
public ICollection<Reservation> Reservations =
new List<Reservation>();
}
I'm using this query:
public async Task<IEnumerable<Person>> GetPersonsAndReservations()
{
return await _context.Persons.Include(p => p.Reservations).ToListAsync();
}
I keep getting the following exception:
ArgumentException: The Include property lambda expression 'p => p.Reservations' is invalid. The expression should represent a property access: 't => t.MyProperty'. To target navigations declared on derived types, specify an explicitly typed lambda parameter of the target type, E.g. '(Derived d) => d.MyProperty'.
Is there anything I'm doing wrong here?