Skip to main content
.NET 6.0+

Session.PreFetchAsync(XPClassInfo, IEnumerable, CancellationToken, String[]) Method

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

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v23.2.dll

NuGet Package: DevExpress.Xpo

Declaration

public Task PreFetchAsync(
    XPClassInfo classInfo,
    IEnumerable objects,
    CancellationToken cancellationToken,
    params string[] propertyPaths
)

Parameters

Name Type Description
classInfo XPClassInfo

An XPClassInfo object that contains metadata information. This data specifies the parent object that needs associated collection data loading and delayed property loading.

objects IEnumerable

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”).

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 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(session.GetClassInfo<Person>(), people, cancellationToken, nameof(PhoneNumbers));
See Also