help refactor some code

Page 1 of 1

0 Replies - 435 Views - Last Post: 30 January 2013 - 02:06 PM Rate Topic: -----

#1 ray1234   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

help refactor some code

Posted 30 January 2013 - 02:06 PM


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;





Is This A Good Question/Topic? 0
  • +

Page 1 of 1