Session.PreFetchAsync(IEnumerable, XPMemberInfo, IEnumerable, CancellationToken) Method
Asynchronously forces associated collection data loading for specified parent objects.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v24.2.dll
NuGet Package: DevExpress.Xpo
#Declaration
public Task PreFetchAsync(
IEnumerable objects,
XPMemberInfo collectionInObjects,
IEnumerable collectionsContent,
CancellationToken cancellationToken = default(CancellationToken)
)
#Parameters
Name | Type | Description |
---|---|---|
objects | IEnumerable | An IEnumerable list of parent objects. |
collection |
XPMember |
An XPMember |
collections |
IEnumerable | An IEnumerable list of the collection’s content. If the collection |
#Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
cancellation |
Cancellation |
null | A Cancellation |
#Returns
Type | Description |
---|---|
Task | A Task that forces associated collection data loading for specified parent objects. |
#Remarks
By default, data is loaded automatically when you access a persistent object’s nested collection for the first time. The PreFetchAsync loads all associated collection data for specified parent objects, before these collections are accessed. No additional SQL queries for this data will be performed later.
using System.Threading;
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
// ...
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
CancellationToken cancellationToken = cancellationTokenSource.Token;
XPCollection<Person> people = new XPCollection<Person>(session);
XPMemberInfo phoneNumbersInfo = session.GetClassInfo(typeof(Person)).GetMember(nameof(PhoneNumbers));
XPCollection<PhoneNumber> phoneNumbers = new XPCollection<PhoneNumber>(session);
await session.PreFetchAsync(people, phoneNumbersInfo, phoneNumbers, cancellationToken);