Transforming row query results to collections and lists

The result of a row query returned by the select method with parameters is an IQueryResult. A row query result is iterable, so you can use it directly in a for loop without transformation.

If you need a different iterable type, you can convert the query result objects of row queries to lists, arrays, collections, and sets by using the conversion methods:

  • toCollection
  • toList
  • toSet
  • toTypedArray

For example, you can use a conversion method on the returned value from the transformQueryRow method to produce a Collection of data transfer objects.

These conversion methods run the query and materialize the results into memory. If your result set is large, running these methods can exceed the available memory. For large result sets, best practice is to set the page size to prefetch query results.

The where method is not applicable on lists, arrays, collections, or sets returned by conversion methods on result objects. Instead, apply all selection criteria to query objects by using predicate methods before calling the select method.

See also