gpt4 book ai didi

c# - 通过 Entity Framework 6 中另一个表中的外键获取记录

转载 作者:太空狗 更新时间:2023-10-30 01:01:44 24 4
gpt4 key购买 nike

我需要将所有座位附加到特定预订。

我有这些类(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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com