Skip to main content
All docs
V24.1
.NET 6.0+

Session.PreFetchAsync<T>(IEnumerable<T>, CancellationToken, String[]) Method

Asynchronously forces associated collection data loading and delayed property loading for specified parent objects.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v24.1.dll

NuGet Package: DevExpress.Xpo

Declaration

public Task PreFetchAsync<T>(
    IEnumerable<T> objects,
    CancellationToken cancellationToken,
    params string[] propertyPaths
)

Parameters

Name Type Description
objects IEnumerable<T>

An IEnumerable list of parent objects.

cancellationToken CancellationToken

A CancellationToken object that delivers a cancellation notice to the running operation.

propertyPaths String[]

An array of strings that are the collection property and delayed property names, or property paths (e.g, “ChildCollection.AnotherChildCollection”).

Type Parameters

Name Description
T

The type of elements in the list of parent objects.

Returns

Type Description
Task

A Task that forces associated collection data loading and delayed property loading for specified parent objects.

Remarks

By default, data is loaded automatically when you access a nested collection or delayed property for the first time. When the PreFetchAsync<T> method is called, all associated collection data and delayed properties are loaded at once for specified parent objects. No additional SQL queries for this data will be will be performed later.

using System.Threading;
using DevExpress.Xpo;
// ...
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
CancellationToken cancellationToken = cancellationTokenSource.Token;
XPCollection<Person> people = new XPCollection<Person>(session);
await session.PreFetchAsync<Person>(people, cancellationToken, nameof(PhoneNumbers));
See Also