Database Reference
In-Depth Information
hotel.Rooms.Add(r101);
hotel.Rooms.Add(es201);
hotel.Rooms.Add(es301);
context.Hotels.Add(hotel);
context.SaveChanges();
}
using (var context = new EFRecipesEntities())
{
// Assume we have an instance of hotel
var hotel = context.Hotels.First();
// Explicit loading with Load() provides opportunity to filter related data
// obtained from the Include() method
context.Entry(hotel)
.Collection(x => x.Rooms)
.Query()
.Include(y => y.Reservations)
.Where(y => y is ExecutiveSuite && y.Reservations.Any())
.Load();
Console.WriteLine("Executive Suites for {0} with reservations", hotel.Name);
foreach (var room in hotel.Rooms)
{
Console.WriteLine("\nExecutive Suite {0} is {1} per night",
room.RoomId.ToString(), room.Rate.ToString("C"));
Console.WriteLine("Current reservations are:");
foreach (var res in room.Reservations.OrderBy(r => r.StartDate))
{
Console.WriteLine("\t{0} thru {1} ({2})", res.StartDate.ToShortDateString(),
res.EndDate.ToShortDateString(), res.ContactName);
}
}
}
The following is the output of the code shown in Listing 5-22:
Executive Suites for Grand Seasons Hotel with reservations
Executive Suite 65 is $299.95 per night
Current reservations are:
1/18/2010 thru 1/28/2010 (Bill Meyers)
3/12/2010 thru 3/14/2010 (Roberta Jones)
Executive Suite 64 is $79.95 per night
Current reservations are:
2/5/2010 thru 2/6/2010 (Robin Rosen)
Executive Suite 66 is $179.95 per night
Search WWH ::




Custom Search