hi,
I was wondering if someone can help me refactor this code further if possible.
this is a method which takes a reservation collection holding reservations of updated data. the method then intends to find those reservations in the Reservation table(database) and update those relevant records. I feel like i made a bit of a dog's dinner with this, as i feel there must be a simpler way of achiving this task..
in my method, i have a list variable, that contains all the reservations for a certain video ID. the problem with this, is if i had 2000 reservations in the reservation table, my code would loop through the whole table just to retrive 4 or 5 records. so i'm wondering if theres a way around this overhead.
in general i'm just wondering if this can be written more efficiently.
here's the code:
thanks,
ray
I was wondering if someone can help me refactor this code further if possible.
this is a method which takes a reservation collection holding reservations of updated data. the method then intends to find those reservations in the Reservation table(database) and update those relevant records. I feel like i made a bit of a dog's dinner with this, as i feel there must be a simpler way of achiving this task..
in my method, i have a list variable, that contains all the reservations for a certain video ID. the problem with this, is if i had 2000 reservations in the reservation table, my code would loop through the whole table just to retrive 4 or 5 records. so i'm wondering if theres a way around this overhead.
in general i'm just wondering if this can be written more efficiently.
here's the code:
public void UpdateReservationPriority(List<Reservation> ReservationCollection) { using( var a = new videoRentalEntities()) { List<Reservation> list = a.Reservations.Where(x => x.Video_ID == ReservationCollection[0].Video_ID).ToList(); for(int i =0; i < ReservationCollection.Count; i++) { Reservation reservation = list.Find(x => x.Member_ID == ReservationCollection[i].Member_ID); reservation.Priority_Level = ReservationCollection[i].Priority_Level; } a.SaveChanges(); } }
thanks,
ray