All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
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.

Implement Dependent Reference Properties (XPO)

  • 3 minutes to read

This lesson explains how to implement properties whose values can depend on other properties.

You will add a new Manager property to the Contact class. The editor for this property will display a list of managers who work in the same department.

Step-by-Step Instructions

  1. Add a new Manager property of the Contact type to the Contact class.

    [DefaultClassOptions]
    public class Contact : Person {
        //...
        private Contact manager;
        public Contact Manager {
           get { return manager; }
           set { SetPropertyValue(nameof(Manager), ref manager, value); }
        }
        //...
    }
    
  2. Apply the DataSourceProperty and DataSourceCriteria attributes to the newly added property.

    [DefaultClassOptions]
    public class Contact : Person {
        //...
        [DataSourceProperty("Department.Contacts", DataSourcePropertyIsNullMode.SelectAll)]
        [DataSourceCriteria("Position.Title = 'Manager' AND Oid != '@This.Oid'")]
        public Contact Manager {
            // ...
        }
        // ...
    }
    
  3. Run the application.

    Add the following objects:

    • a Department object (for example, “Developer Department”)
    • multiple Contact objects with the Department property set to “Developer Department”
    • multiple Position objects (for example, “Manager”, “Developer”).

    For the newly added contacts, set the Position property to:

    • “Manager” (for multiple Contact objects);
    • “Developer” (for other Contact objects).

    xaf ASP.NET Core Blazor list view

    Create a new Contact object. In the Contact Detail View, specify the Department property and expand the Manager lookup editor. Notice the following:

    • The Department property of the listed objects is the same as those you specified above.
    • The Position property is set to “Manager” for each of the listed objects.

    xaf ASP.NET Core Blazor prefilter lookup items

Detailed Explanation

You can use integrated XAF designers to implement the same behavior without code. For details, refer to the following lesson: Filter Lookup Editor Data Source.

The DataSourceProperty Attribute

The DataSourceProperty attribute accepts two parameters. The first one specifies the path to the lookup list. The second parameter is optional. It specifies how the lookup items are populated if the application could not find any items from the path.

In this tutorial, the second parameter is set to SelectAll. You can also set the SelectNothing or CustomCriteria values. In the latter case, a third parameter is required to specify criteria.

The DataSourceCriteria Attribute

With the DataSourceCriteria attribute applied, the Manager lookup editor contains Contact objects that satisfy the criteria specified in the attribute parameter.

Next Lesson

Implement Property Value Validation in Code (XPO)

See Also