What is the structure of IQueryable?

using (var nosql = new DbHelper("Feed")) 
{
    var watch = Stopwatch.StartNew();
    nosql.CollectionName = "rawhi";
    var x = nosql.GetRecords<Event>(p => true, 0, 1000000);
    //GridView1.DataSource = x;
    //GridView1.DataBind();
    watch.Stop();
    long milliseconds = watch.ElapsedMilliseconds;
    Response.Write(milliseconds);
}

xis a type variable IQueryable.

When I run this code, the result is: 0

So, I am wondering if data is stored in xvar or not?

+3
source share
2 answers

The query will be evaluated lazily, so until something tries to list the results, the query is not actually executed or the results are returned. In your code example, you set the request up, but you didn't actually run it. If you return your data binding code that will actually list the result and thus execute it.

For testing purposes, you can force enumeration as follows:

x.ToList();
+4
source

- x, , .

:

foreach(var item in x)
{
  //do something
}

, ToList(), x - , :

  var x = nosql.GetRecords<Event>(p => true, 0, 1000000).ToList();
0

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


All Articles