The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

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

Asynchronously forces associated collection data loading for specified parent objects.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.2.dll

Declaration

public Task PreFetchAsync<T>(
    IEnumerable<T> objects,
    string collectionInObjects,
    IEnumerable collectionsContent,
    CancellationToken cancellationToken
)
Public Function PreFetchAsync(Of T)(
    objects As IEnumerable(Of T),
    collectionInObjects As String,
    collectionsContent As IEnumerable,
    cancellationToken As CancellationToken
) As Task
public Task PreFetchAsync<T>(
    IEnumerable<T> objects,
    string collectionInObjects,
    IEnumerable collectionsContent,
    CancellationToken cancellationToken
)
Public Function PreFetchAsync(Of T)(
    objects As IEnumerable(Of T),
    collectionInObjects As String,
    collectionsContent As IEnumerable,
    cancellationToken As CancellationToken
) As Task

Parameters

Name Type Description
objects IEnumerable<T>

An IEnumerable list of parent objects.

collectionInObjects String

A string which is the name of the associated collection property.

collectionsContent IEnumerable

An IEnumerable list of the collection's content. If the collectionInObjects data was previously loaded, you can avoid reloading it by passing the loaded data to the collectionsContent parameter. Note that if this parameter does not contain a part of the collection's content, this part will not be loaded from a database.

cancellationToken CancellationToken

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

Parameters

Name Type Description
objects IEnumerable<T>

An IEnumerable list of parent objects.

collectionInObjects String

A string which is the name of the associated collection property.

collectionsContent IEnumerable

An IEnumerable list of the collection's content. If the collectionInObjects data was previously loaded, you can avoid reloading it by passing the loaded data to the collectionsContent parameter. Note that if this parameter does not contain a part of the collection's content, this part will not be loaded from a database.

cancellationToken CancellationToken

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

Returns

Type Description
Task

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

Returns

Type Description
Task

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

Type Parameters

Name Description
T

Type Parameters

Name Description
T

Remarks

By default, data is loaded automatically when you access a nested collection for the first time. The PreFetchAsync<T> method loads required associated collection data for a parent object at once. No additional SQL queries for this data 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);
XPCollection<PhoneNumber> phoneNumbers = new XPCollection<PhoneNumber>(session);
await session.PreFetchAsync<Person>(people, nameof(PhoneNumbers), phoneNumbers, cancellationToken);
See Also