public override SRental GetRentalByPayment(int id)
{
//a deliberate inefficient query
List<SRental> srentlist = new List<SRental>();
SRental lightweightrental = new SRental();
using (SakilaEntities dc = new SakilaEntities())
{
var model = from r in dc.payments
where r.payment_id == id
select r;
List<payment> pList = model.ToList<payment>();
payment p = pList[0];
var rentalModel = from r in dc.rentals
where r.rental_id == p.rental_id
orderby (r.return_date) //this is not neccessary but put in here for analysis (SQL end)
select r;
List<rental> rentalList = rentalModel.ToList<rental>();
simulator.PerformanceSimulation();
rental hwrental = rentalList[0];
if (hwrental.return_date.HasValue)
{
lightweightrental = lightweightrental.Createrental(hwrental.rental_id, hwrental.rental_date, hwrental.return_date, hwrental.inventory_id, hwrental.customer_id, hwrental.staff_id, hwrental.last_update);
}
else
{
lightweightrental = lightweightrental.Createrental(hwrental.rental_id, hwrental.rental_date, hwrental.inventory_id, hwrental.customer_id, hwrental.staff_id, hwrental.last_update);
}
lightweightrental.Filmtitle = hwrental.inventory.film.title;
}
return lightweightrental;
}