The requested page is not available for the requested platform. You are viewing the content for Default platform.
All docs
V19.2
19.2 (EAP/Beta)
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

XPObjectSpace.PreFetchAsync(Object, String[], CancellationToken) Method

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

Namespace: DevExpress.ExpressApp.Xpo

Assembly: DevExpress.ExpressApp.Xpo.v19.2.dll

Declaration

public Task PreFetchAsync(
    object collection,
    string[] propertyNames,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function PreFetchAsync(
    collection As Object,
    propertyNames As String(),
    cancellationToken As CancellationToken = Nothing
) As Task

Parameters

Name Type Description
collection Object

A collection of parent objects.

propertyNames String[]

An array of strings which are the names of the associated collection properties.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken null

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

Returns

Type Description
Task

A Task object.

Remarks

The following code demonstrates how you can use this method in a WinForms-specific View Controller.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Xpo;
using MainDemo.Module.BusinessObjects;
using System;
using System.Threading;
// ...
public class AsyncAssignedToInfoController : ObjectViewController<ListView, DemoTask> {
    View contactView = null;
    public AsyncAssignedToInfoController() : base() {
        SimpleAction showAssignedToInfoAction = new SimpleAction(this, "Assigned contact's info", "Edit");
        showAssignedToInfoAction.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
        showAssignedToInfoAction.Execute += showAssignedToInfoAction_Execute;
    }
    async private void showAssignedToInfoAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
        XPObjectSpace contactObjectSpace = (XPObjectSpace)Application.CreateObjectSpace(typeof(Contact));
        contactView = Application.CreateDetailView(contactObjectSpace, "Contact_DetailView", true);
        e.ShowViewParameters.CreatedView = contactView;
        Contact obj = null;
        if (ViewCurrentObject.AssignedTo != null) {
            obj = (Contact)await contactObjectSpace.GetObjectAsync(ViewCurrentObject.AssignedTo);
            Contact[] contacts = new Contact[] { obj };
            await contactObjectSpace.PreFetchAsync(contacts, new string[] { "Tasks" });
        }
        if (obj == null) {
            obj = contactObjectSpace.CreateObject<Contact>();
            contactObjectSpace.Committed += contactObjectSpace_Committed;
        }
        contactView.CurrentObject = obj;
    }
    private void contactObjectSpace_Committed(object sender, EventArgs e) {
        ViewCurrentObject.AssignedTo = ObjectSpace.GetObject(contactView.CurrentObject) as Contact;
    }
}
See Also