Database Reference
In-Depth Information
Figure 5-24. A model for a hotel reservation system
Let's assume we have an instance of a Hotel entity. To retrieve the executive suite rooms for the hotel, see which
have reservations, and order them by room rate, use the pattern shown in Listing 5-22.
Listing 5-22. Filtering and Ordering an Entity Collection Using Explicit Loading Along with the Entry() and
Query() Methods
using (var context = new EFRecipesEntities())
{
var hotel = new Hotel { Name = "Grand Seasons Hotel" };
var r101 = new Room { Rate = 79.95M, Hotel = hotel };
var es201 = new ExecutiveSuite { Rate = 179.95M, Hotel = hotel };
var es301 = new ExecutiveSuite { Rate = 299.95M, Hotel = hotel };
var res1 = new Reservation { StartDate = DateTime.Parse("3/12/2010"),
EndDate = DateTime.Parse("3/14/2010"), ContactName = "Roberta Jones", Room = es301 };
var res2 = new Reservation { StartDate = DateTime.Parse("1/18/2010"),
EndDate = DateTime.Parse("1/28/2010"), ContactName = "Bill Meyers", Room = es301 };
var res3 = new Reservation { StartDate = DateTime.Parse("2/5/2010"),
EndDate = DateTime.Parse("2/6/2010"), ContactName = "Robin Rosen", Room = r101 };
es301.Reservations.Add(res1);
es301.Reservations.Add(res2);
r101.Reservations.Add(res3);
 
Search WWH ::




Custom Search