Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Results View from variable in code

As shown in the above image, when I press on the ResultsView, it opens a new list which contains [0] and [1]. However, in my code, when I write sessionQueryable[0] it says syntax error. How can I access what's in the ResultsView?

like image 641
petko_stankoski Avatar asked Dec 24 '11 13:12

petko_stankoski


1 Answers

The debugger is showing you the internal structure behind the IQueryable interface, but you should not program against that, though, since there is no guarantee that you'll get the same structure each time.

IQueryable lists cannot be accessed by index using []. You'd need to turn it into an IList to access it by index:

var list = user.Sessions.ToList();

Or query the sessions by some other method using the IQueryable interface, for example Skip() and Take():

var first  = sessionsQueryable.Take(1);         // First item
var second = sessionsQueryable.Skip(1).Take(1); // Second item
like image 112
D Stanley Avatar answered Oct 01 '22 04:10

D Stanley