현재 계정의 모든 예약을 나열 할 수 있지만 문제가있는 페이지에서 작업하고 있습니다. 예약에 지정된 방에서 모든 속성에 액세스하고 싶습니다. 그러나이를 달성하는 방법을 잘 모르겠습니다.테이블의 ID에서 속성에 액세스하는 방법
룸 모델 :
public class Room
{
public int RoomID { get; set; }
public int RoomNumber { get; set; }
public string RoomType { get; set; }
public string Image { get; set; }
public int Price { get; set; }
public int Adults { get; set; }
public int Childs { get; set; }
public bool SmokingRoom { get; set; }
public bool IsOccupied { get; set; }
public Floor Floor { get; set; }
public virtual ICollection<Booking> Bookings { get; set; }
}
예약 모델 :
public class Booking
{
public int BookingID { get; set; }
public Account Account { get; set; }
public DateTime DateOfReservation { get; set; }
public DateTime Arrival { get; set; }
public DateTime Departure { get; set; }
public int Adults { get; set; }
public int Children { get; set; }
public Room Room { get; set; }
public bool CheckIn { get; set; }
public bool CheckOut { get; set; }
public string Status { get; set; }
}
Databasehandler있어서
public static List<Booking> GetAllBookingsByAccount(int id)
{
HotelDbContext context = new HotelDbContext();
var bookings = context.Bookings.Where(b => b.Account.AccountID == id).ToList();
return bookings;
}
보기 :
감사합니다! 당신은 EF가 속성을 재정의 할 수 있도록 가상으로 속성을 설정해야 할 일을
var bookings = context.Bookings.Include("Room").Where(b => b.Account.AccountID == id).ToList();
EF를 사용하고 Room 개체를 Booking 개체에 대해 가상으로 사용하려면 드릴 다운 할 수 있어야합니다. 그렇지 않다면 두 번째 쿼리를 설정해야합니다. 클래스 정의를 게시 할 수 있습니까? – nurdyguy
@nurdyguy 질문에 – josephzigler
을 추가했습니다. 디버거를 사용하여 단계를 밟으면 방으로 드릴 다운 할 수 있습니까? 또한, 당신은 Entity Framework를 사용하고 있습니까? (nm에서 태그를보십시오 ...) – nurdyguy