TechTalk Genome v4.2

Paging

set .GetRange(0,element count)
element count
The number of elements to be fetched from the set.
set
An OQL expression returning a Set<T> of scalars or persistent objects.

Return Value

A Set<T> containing up to element count elements of the source set.

Remarks

GetRange() copies up to element count elements of the source set, starting from element 0, to the resulting Set<T>.
As the element order in a Set<T> is not deterministic, GetRange() is often used in combination with ordering.
This corresponds to a SELECT TOP n in SQL.

GetRange() in server-side OQL only supports retrieving elements from the 0 position of the source set.
In client-side OQL, Set<T>.GetRange() can also be used to retrieve arbitrary pages of a set. In that case, Genome can fetch all elements up to the desired page of the set and drop elements that are not needed from the underlying datareader. The client side behaviour of the GetRange() method can be influenced by using the overload, which requires a GetRangeMethod argument.

Note that, even when using GetRange(0,1), the result is still a Set<T> with 0 or 1 elements. Use ToObject in order to directly return an instance of the single element contained in the set.

Quick Reference

OQL
extentof(Animal).GetRange(0,1)

C#
Set<Animal> animals = myDB.Extent<Animal>().GetRange(0,1);


//GetRange on the client side also supports fetching pages Set<Animal> animals = myDB.Extent<Animal>().GetRange(2,4);

SQL
SELECT TOP 1 * FROM Animal


SELECT TOP 6 * FROM Animal

Examples

                    
<Type name="Cage">
    ...

    <Member name="TenOldestInhabitants" Oql="Inhabitants.OrderBy([Age descending]).GetRange(0,10)"/>
     
    ...
</Type>
                    
                

See Also

Set<T>.GetRange | OqlReference.Chapter26