Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/Samples: Looping through entire queryable #36

Open
christophwille opened this issue Mar 23, 2023 · 4 comments
Open

Docs/Samples: Looping through entire queryable #36

christophwille opened this issue Mar 23, 2023 · 4 comments
Labels
up for grabs Up for grabs issue

Comments

@christophwille
Copy link

The current sample is for interactive - how about a sample for headless where the entire purpose is to not bring in everything at once? (think huge tables that simply need to scanned)

@mrahhal
Copy link
Owner

mrahhal commented Mar 23, 2023

Can you elaborate? What kind of sample are we talking about exactly? If by "not bring in everything at once" you mean columns, creating a dto isn't that much different.

@christophwille
Copy link
Author

christophwille commented Mar 23, 2023

Roughly this:

int rows = 0;
do
{
  rows = 0;
  await foreach (var item in ctx.MyDbSet.Orderby(b => b.Id).Where(b => b.Id > lastId).Take(100))
  {
    // do something here
    rows++;
    lastId = item.Id;
  }
  ctx.ChangeTracker.Clear();
} while (rows == 100);

Maybe also thinking a bit about the PageIterator from MS Graph SDK 5.

@mrahhal
Copy link
Owner

mrahhal commented Mar 23, 2023

Ah, you're talking about batching. There are very specific use cases for this and the way you would deal with doing some work in batches is pretty much the same in non KeysetPagination code (but instead of storing a lastId you would store the last entity). This is particularly simple because you'll only ever need a keyset containing the id for a scan.

But I do see that KeysetPagination is particularly efficient in such batched scanning operations compared to the classic method, so might be worth it to have a sample on this after all.

@mrahhal mrahhal added the up for grabs Up for grabs issue label May 11, 2023
@skwasjer
Copy link

The example I provided for a different issue seems relevant here, even though I encapsulated it. It could also be rewritten into a convenient extension method btw without the MediatR sugar/encapsulation ;)

#58 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
up for grabs Up for grabs issue
Projects
None yet
Development

No branches or pull requests

3 participants