В настоящее время я работаю на странице, где я могу перечислить все заказы из учетной записи, но столкнувшись с проблемой. Я хотел бы получить доступ ко всем свойствам из комнаты, назначенной для бронирования, но я не совсем уверен, как этого добиться.Как получить доступ к свойствам из идентификатора в таблице
Модель номер:
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;
}
Вид:
@if (Model.Bookings.Count != 0)
{
<table>
<thead>
<tr>
<th>Arrival</th>
<th>Departure</th>
<th>Hotel</th>
<th>Room</th>
<th>Persons</th>
<th>Price</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach (var booking in Model.Bookings)
{
<tr>
<td>@booking.Arrival.ToShortDateString()</td>
<td>@booking.Departure.ToShortDateString()</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>@booking.TotalPersons</td>
<td></td>
<td>@booking.Status</td>
</tr>
}
</tbody>
</table>
}
else
{
<p>You currently do not have any bookings.</p>
}
Благодарим за ваше время!
Если вы используете EF и имеете объект «Комната» как виртуальный на объекте «Бронирование», вы должны быть в состоянии развернуть его. Если нет, вам придется настроить второй запрос. Можете ли вы опубликовать определения классов? – nurdyguy
@nurdyguy Я добавил их в вопрос – josephzigler
Когда вы переходите через отладчик, можете ли вы развернуть его в Комнату? Кроме того, вы используете Entity Framework (nm см. Его в тегах сейчас ...) – nurdyguy