I am trying to understand a situation where I have an entity infrastructure on .net 3.5 sp1 + MySQL 6.1.2.0 as a provider. It includes the following code:
Response.Write("Products: " + plist.Count() + "<br />"); var total = 0; foreach (var p in plist) {
In general, the total production varies in each run, and it does not correspond to the total amount in the plist. It varies widely: from ~ 1/5 to half.
Inside foreach, there is no control flow code, i.e. do not interrupt, continue, try / catch, conditions around total ++, everything that can affect the score. As a confirmation, there are other totals recorded within the cycle associated with the actions, and they correspond to lower and higher total runs.
I cannot find the reason for the above, except for anything in the entity infrastructure or the mysql provider that causes it to complete foreach when the element is retrieved.
The foreach body can have good changes over time, since the actions are related to access to files and the network, my best shot is when the .net code goes beyond a certain threshold, there is some type of timeout in the base structure / provider and instead In order to raise an exception, it silently reports the absence of elements for enumeration .
Can someone give light in the above scenario and / or confirm if the framework / mysql operator entity has the above behavior?
Update 1: I cannot reproduce the behavior using Thread.Sleep in a simple foreach in a test project, not sure where else to look for this strange behavior: (.
Update 2: in the example above .Count () always returns the same + the correct number of elements. Using ToList or ToArray, as suggested, allows you to bypass the problem as expected (without flow control instructions in the foreach body) and both coincidence + matches do not change with each run.
I am interested in what causes this behavior in the framework + mysql entity. It would really not be necessary to change the code in all projects that use the framework + mysql entity to do .ToArray before listing the results, because I don't know when it will swallow some results. Or, if I do, at least I know what / why it happened.