I need to get all seats attached to a specific reservation.
I have these classes:
public class Seat
{
public Guid Id { get; set; }
public string RowNumber { get; set; }
public int SeatNumber { get; set; }
}
public class ReservationSeat
{
public Guid Id { get; set; }
public Guid ReservationId { get; set; }
public Guid SeatId { get; set; }
public Reservation Reservation { get; set; }
public Seat Seat { get; set; }
}
I have tried with this linq to entities statement but with no luck. It seems to return all the seats from the seats table.
public static List<Seat> GetSeatsForReservation(Guid reservationId)
{
using (var db = new EntityContext())
{
return db.Seats.Where(s => db.ReservationSeat
.Select(rs => rs.ReservationId)
.Contains(reservationId)).ToList();
}
}
Try:
public static List<Seat> GetSeatsForReservation(Guid reservationId)
{
var db= new EntityContext();
return (from s in db.ReservationSeat
where s.ReservationID==Guid
select s.seat).ToList();
}