tolist

Calling ToList() on ConcurrentDictionary<TKey, TValue> while adding items

橙三吉。 提交于 2019-12-04 02:55:57
问题 I've run into an interesting issue. Knowing that the ConcurrentDictionary<TKey, TValue> is safely enumerable while being modified, with the (in my case) unwanted side-effect of iterating over elements that may disappear or appear multiple times, I decided to create a snapshot myself, using ToList() . Since ConcurrentDictionary<TKey, TValue> also implements ICollection<KeyValuePair<TKey, TValue>> , this causes the List(IEnumerable<T> collection) to be used, which in turn creates an array in

Rules of thumb for when to call ToList when returning LINQ results

空扰寡人 提交于 2019-12-04 02:04:15
I'm looking for rules of thumb for calling ToList/ToArray/MemoizeAll(Rx) on IEnumerables , as opposed to returning the query itself when returning IEnumerable of something. Often I find that it is better to just return the query and let the caller decide whether a list is needed or not, but sometimes it can come back and bite you in the rear due to the lazy nature of linq. I want to collect guidelines such as: Call ToList if: you create new objects (eg. in a select) you have side effects in your query Otherwise, return the query First off, you should NEVER have side effects in a query. That is

entity .ToList() generates a System.OutOfMemoryException

大兔子大兔子 提交于 2019-12-02 09:58:45
问题 I have a table with half a million rows. I need to update every single row but the ToList() fails: List<Contacts> allContacts = objDatabase.Contacts.ToList(); I get a System.OutOfMemoryException every time. Is there a way around this? I already have the App.Config workaround but still no go: <gcAllowVeryLargeObjects enabled="true" /> I'm on a 64bit machine with 8GB of RAM 回答1: Here is a solution using chunking. It will dispose of the container (and the downloaded entities) after every chunk.

entity .ToList() generates a System.OutOfMemoryException

元气小坏坏 提交于 2019-12-02 07:26:54
I have a table with half a million rows. I need to update every single row but the ToList() fails: List<Contacts> allContacts = objDatabase.Contacts.ToList(); I get a System.OutOfMemoryException every time. Is there a way around this? I already have the App.Config workaround but still no go: <gcAllowVeryLargeObjects enabled="true" /> I'm on a 64bit machine with 8GB of RAM Here is a solution using chunking. It will dispose of the container (and the downloaded entities) after every chunk. Memory should be released by the GC long before your system runs out of memory. int chunkSize = 50; int

Does foreach execute the query only once?

断了今生、忘了曾经 提交于 2019-11-28 09:42:55
I have a list of items and a LINQ query over them. Now, with LINQ's deferred execution, would a subsequent foreach loop execute the query only once or for each turn in the loop? Given this example (Taken from Introduction to LINQ Queries (C#), on MSDN ) // The Three Parts of a LINQ Query: // 1. Data source. int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 }; // 2. Query creation. // numQuery is an IEnumerable<int> var numQuery = from num in numbers where (num % 2) == 0 select num; // 3. Query execution. foreach (int num in numQuery) { Console.Write("{0,1} ", num); } Or, in other words, would

How to convert LINQ query result to List?

[亡魂溺海] 提交于 2019-11-27 23:29:53
I need to convert linq query result to list. I tried the following code: var qry = from a in obj.tbCourses select a; List<course> lst = new List<course>(); lst = qry.ToList(); The following error occurred for the above code: Cannot implicitly convert type System.Collections.Generic.List<Datalogiclayer.tbcourse> to System.Collections.Generic.List<course> dellgg No need to do so much works.. var query = from c in obj.tbCourses where ... select c; Then you can use: List<course> list_course= query.ToList<course>(); It works fine for me. goggles1200 List<course> = (from c in obj.tbCourses select

Pandas DataFrame column to list [duplicate]

心已入冬 提交于 2019-11-27 06:01:21
This question already has an answer here: How do I convert a pandas Series or index to a Numpy array? 7 answers get list from pandas dataframe column 6 answers I am pulling a subset of data from a column based on conditions in another column being met. I can get the correct values back but it is in pandas.core.frame.DataFrame. How do I convert that to list? import pandas as pd tst = pd.read_csv('C:\\SomeCSV.csv') lookupValue = tst['SomeCol'] == "SomeValue" ID = tst[lookupValue][['SomeCol']] #How To convert ID to a list Akavall Use .values to get a numpy.array and then .tolist() to get a list.

Does foreach execute the query only once?

ぃ、小莉子 提交于 2019-11-27 02:35:51
问题 I have a list of items and a LINQ query over them. Now, with LINQ's deferred execution, would a subsequent foreach loop execute the query only once or for each turn in the loop? Given this example (Taken from Introduction to LINQ Queries (C#), on MSDN) // The Three Parts of a LINQ Query: // 1. Data source. int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 }; // 2. Query creation. // numQuery is an IEnumerable<int> var numQuery = from num in numbers where (num % 2) == 0 select num; // 3. Query

How to convert LINQ query result to List?

白昼怎懂夜的黑 提交于 2019-11-26 21:28:39
问题 I need to convert linq query result to list. I tried the following code: var qry = from a in obj.tbCourses select a; List<course> lst = new List<course>(); lst = qry.ToList(); The following error occurred for the above code: Cannot implicitly convert type System.Collections.Generic.List<Datalogiclayer.tbcourse> to System.Collections.Generic.List<course> 回答1: No need to do so much works.. var query = from c in obj.tbCourses where ... select c; Then you can use: List<course> list_course= query