Is this the correct way to convert a List to an IQueryable List? List<Family> families = new List<Family>(); using (SqlConnection myConnection = new SqlConnection(connectionString)) { myConnection. Open(); SqlDataReader nwReader = selectTemp_DistinctFamilies_Command. ExecuteReader(); while (nwReader.
The simple answer is that unless you add the record to the underlying datastore that the Iqueryable is querying, you can't add a new record into an IQueryable. So if you are using LinqToSql then you would have to add a row into the table that the IQueryable was querying in order to "add" a row into the IQueryable.
Here is a test that i have setup this evening. It was made to prove something different, but the outcome was not quite as i expected. I'm running a test with 10000 random queries on an IQueryable and while testing i found out that if i do the same on a List, my test is 20 times faster.
List<int> list = new List<int>() { 1, 2, 3, 4, };
IQueryable<int> query = list.AsQueryable();
If you don't see the AsQueryable()
method, add a using statement for System.Linq
.
Use the AsQueryable<T>()
extension method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With