Search code examples
c#petapoconpoco

NPoco/Petapoco: Dataset too large for Fetch<T>


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?


Solution

  • 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.