Access to the presentation of results from a variable in code

As shown in the picture above, when I click on ResultsView, it opens a new list containing [0] and [1] . However, in my code, when I write sessionQueryable[0] , it talks about a syntax error. How can I access the results in the Results view?

+8
source share
1 answer

The debugger shows you the internal structure of the IQueryable interface, but you should not program against this, since there is no guarantee that you will receive the same structure every time.

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

 var list = user.Sessions.ToList(); 

Or request sessions using a different method using the IQueryable interface, such as Skip() and Take() :

 var first = sessionsQueryable.Take(1); // First item var second = sessionsQueryable.Skip(1).Take(1); // Second item 
+10
source

Source: https://habr.com/ru/post/904429/


All Articles