I have an Entity Framework query that can return ~ 10,000 rows. This is used to populate a map with pins.
Is there a way to get the results back in blocks that will be as fast as reading everything at once? For example, if I do:
.OrderBy(e => e.Id).Skip(offset).Take(1024)
And read the results back 1K at a time, is that in total, about the same amount of time as reading everything all at once? Or is there another way to do this?
Note, this is not a case of a paged grid where I can make a single call of .Skip(x).Take(pageSize)
and that one call is sufficient until they go to another page. In this case I do need all the results.
The biggest impacts on performance and resource usage would be best case to ensure you are using projection (Select()
) to retrieve just the values you need, or using an AsNoTracking()
query if you do need to load entities. These both ensure EF doesn't bother reading or adding to the tracking cache.
Loading 10k rows of Ids, coords, and maybe a name/label for instance to populate a map area should be no issue to do in one hit if you need all 10k items. Paginating results is more about only needing to display a page of values at a time. If you need 10k items, loading them 1k at a time won't save resources or time. Updating 10k items (if you cannot batch the operation) can save resources by only loading/tracking a subset at a time, so long as you purge the tracking cache between pages.