Equivalents to MoveFirst() and MoveNext()

Aug 19, 2011 at 3:33 PM

Not quite sure if this is a LinQ or Sterling question - is there an equivalent to the ADO style RecordSet MoveFirst and MoveNext functions?

Pseudo-code would be something like this:

// create a persistent iterator

private Iterator _iterator ....

// go to start of sequence

_iterator.First();

// go to next element in sequence

_iterator.Next();

TIA

Aug 19, 2011 at 6:34 PM

OK, need to distinguish between IEnumerable and IEnumerator!

So the pattern is something similar to the code below (error checking omitted). If anyone knows better please clue me in.

            // the query returns the enumerable
            IEnumerable<int> ie = (from k in Database.Query<CompositeImageData, int, int>(CompositeSequenceIndex) select k.Key);
            // from which we get an enumerator
            private IEnumerator<int> _enum = ie.GetEnumerator();
// any instances present?
int total = ie.Count(); if (_enum != null) { // appears to be unsupported // _enum.Reset(); ret = _enum.MoveNext(); }

Coordinator
Aug 21, 2011 at 4:24 PM

My question is - why do you want to have a manual move next? Why not just a simple for ... each loop? It does the same thing but moves the iterator for you. You can always break and continue to keep the iterator moving. I wouldn't try to force the code into patterns you are familiar with because they may not be the right patterns for the technology - try to learn the LINQ patterns and apply those to the code base.