Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

help refactor some code

$
0
0
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:


 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

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>