Hi. Consider such situation. I have a set of classes autmatically generated by Visual studio to support Linq to Sql. I have a table caled PricesSource. Using dbContext I iterate through its rows:
FactEventAnalysisDBDataContext dbContext = new FactEventAnalysisDBDataContext(); var startPrice = new FactEventAnalyzer.PricesSource(); foreach (FactEventAnalyzer.PricesSource curPrice in PriceQuery) { //do smth }
I want to keep a reference to one of 'interesting' records in database to do this I add a reference to interesting record:
startPrice = curPrice;
While iterating I check if curPrice meets some conditions and once I find a record which meets this conditions I want to do some work against startPrice and curPrice:
curChange = determineChangeType(prevPrice: startPrice.Price, curPrice: curPrice.Price, changeThreshold: changeThreshold);
The question is that, is it bad to keep a reference to startPrice directly? How it actually works behind the scene? What the system really does when I tell it to retreive startPrice.Price value? AFAR when you iterate through result set it doesn't try to actually store whole resultset in RAM, so I am afraid that if I will keep a reference to startPrice it will somehow try to store the piece of resultset between startPrice record and curPrice record. Currently I am testing my code against limited amount of data, so resultset is small and code is completed within a second, but what I am a little bit nervous about the moment when I will need to run it against billion of records - it is possible that I will have millions of rows between startPrice and curPrice.