Skip to main content
All docs
V25.1
  • .NET 8.0+

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

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

    Namespace: DevExpress.ExpressApp

    Assembly: DevExpress.ExpressApp.v25.1.dll

    NuGet Package: DevExpress.ExpressApp

    Declaration

    Task PreFetchAsync(
        object collection,
        string[] propertyNames,
        CancellationToken cancellationToken = default(CancellationToken)
    )

    Parameters

    Name Type Description
    collection Object

    A collection of parent objects.

    propertyNames String[]

    An array of strings that are the names of the associated collection properties or delayed 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;
        }
    }
    

    In the current example, the cancellationToken parameter is used for demonstration purposes. You can skip it or use to cancel an asynchronous operation as shown in the CancellationToken topic.

    See Also