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

    DevExpress v25.1 Update — Your Feedback Matters

    Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

    Take the survey Not interested

    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.v25.1.dll

    NuGet Package: DevExpress.ExpressApp.Xpo

    #Declaration

    public 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 which 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