IQueryable with out GetEnumerator (foreach)  
Author Message
ChSchmidt





PostPosted: LINQ Project General, IQueryable with out GetEnumerator (foreach) Top

Can I move manually through the IQueryable collection with out using GetEnumerator (foreach)

I mean:

I have this query

IQueryable<Person> q =

from c in db.Person

select c;

and now I want to work with the Person Objects which I get from the query but without using GetEnumerator (foreach)

Can I move separately through the IQueryable collection



Visual Studio 200827  
 
 
Terotech.Com Ltd





PostPosted: LINQ Project General, IQueryable with out GetEnumerator (foreach) Top

(I haven't tried this)

 

can't you use the indexer

 

<pre>pNo,/pre> - where 'n' is the index

 Sorry,
"open square bracket"n"close square bracket"

(the silly thing recognised the square brackets as formatting!!!!)

 

D

 



 
 
JacobCarpenter





PostPosted: LINQ Project General, IQueryable with out GetEnumerator (foreach) Top

Have a look at ToList() and ToArray(). System.Query defines those extension methods for any IEnumerable<T>.

Jacob.

 
 
Matt Warren





PostPosted: LINQ Project General, IQueryable with out GetEnumerator (foreach) Top

IQueryable is not a collection, it is a query.  Think of it as a description of what you want done when you call GetEnumerator().  Like Jacob mentioned above, if what you want is a list, there is a ToList() method, although it is hard to discover since intellisense is not working for these yet.  ToList() will call GetEnumerator() for you and convert the resulting sequence into a List<T>.