我需要将所有座位附加到特定预订。
我有这些类(class):
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; }
}
我已经尝试使用此 linq to entities 语句,但没有成功。它似乎从 seats 表中返回所有的座位。
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();
}
}
最佳答案
尝试:
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();
}
关于c# - 通过 Entity Framework 6 中另一个表中的外键获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37208329/