0

I have some code which has to process through each record in a dataset, which I've retrieved from the database via

List<Poco> lp = Fetch<Poco>("Select * from X");

My program crashes here with an out-of-memory exception. If I'd do it the old-fashioned way, it would be like this: Create a reader then iterate through each retrieved record. What is the best way to achieve something like this with Npoco / Petapoco?

erict
  • 1,394
  • 2
  • 14
  • 28

1 Answers1

3

You need lazy-loading (where each result is loaded into memory as you iterate the enumerable), rather than eager-loading (where all results are loaded into memory at once).

NPoco seems to use Fetch for eager-loading and Query for lazy-loading.

Try using the Query method.

Matthew King
  • 5,114
  • 4
  • 36
  • 50
  • Wouldn't it get added into the List object as I iterate? Do I need to delete the object to prevent that? – erict Jan 19 '15 at 03:32
  • Query will return an enumerable. The results should be returned one-by-one as you iterate the enumerable, much like how your old-fashioned reader would iterate through each retrieved record. If you don't reference the objects elsewhere, they should be GC'd as usual. – Matthew King Jan 19 '15 at 03:54