Question

Using Linq is there a more efficient way to do this?

 IDataReader reader = qSeats.ExecuteReader();
            var seats = new List<int>();
            using (IDataReader reader = qSeats.ExecuteReader())
            {
                while (reader.Read())
                {
                    seats.Add(Convert.ToInt32(reader.GetInt32(0)));
                }
            }

I saw: How do I load data to a list from a dataReader? However this is the same code I have above, and it seems like there could be faster ways. Like using Linq or seats.AddRange() or some kind of ToList()

Was it helpful?

Solution

DataReader is read-only, forward-only stream of data from a database. The way you are doing it is probably the fastest.

Using the DataReader can increase application performance both by retrieving data as soon as it is available, rather than waiting for the entire results of the query to be returned, and (by default) storing only one row at a time in memory, reducing system overhead. Retrieving Data Using the DataReader

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top