Skip to main content
All docs
V24.2
.NET 8.0+

Implement Dependent Reference Properties

  • 3 minutes to read

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

For this purpose, add a new Manager property to the Employee class. The editor for this property displays a list of managers who work in the same department.

Note

Before you proceed, take a moment to review the previous lessons:

Step-by-Step Instructions

  1. Add the new Manager property to the Employee class:

    using DevExpress.ExpressApp.DC;
    //...
    public class Employee : BaseObject {
        //...
        public virtual Employee Manager { get; set; }
    }
    
  2. Apply the DataSourceProperty and DataSourceCriteria attributes to the newly added property:

    using DevExpress.ExpressApp.DC;
    //...
    public class Employee : BaseObject {
        //...
        [DataSourceProperty("Department.Employees", DataSourcePropertyIsNullMode.SelectAll), DataSourceCriteria("Position.Title = 'Manager'")]
        public virtual Employee Manager { get; set; }
    }
    // ...
    

    In this code, the DataSourceProperty attribute accepts two parameters: dataSourceProperty and mode.

    The dataSourceProperty parameter is a string value that specifies the name of the collection property used as the data source for a List View displayed in a Lookup Property Editor. In this tutorial, you set this parameter to "Department.Employees".

    The mode 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, you set it to SelectAll.

    You can also set it to SelectNothing or CustomCriteria. In the latter case, you also have to use the DataSourcePropertyIsNullCriteria parameter to specify criteria to filter the List View by the target property’s Lookup Property Editor.

    The DataSourceCriteria attribute restricts the Manager lookup editor items to specific objects. With the "Position.Title = 'Manager'" filter, the lookup editor displays only the Employee objects whose Position property value is "Manager".

  3. Add a migration and update the database. See the following section for details: Use a DBMS: Setup Migrations.

  4. Run the application and make the following changes:

    • Add a Department object (for example, “Development”).
    • Add multiple Position objects (for example, “Manager”, “Developer”, “QA”).
    • Add multiple Employee objects with the Department property set to “Development”.
    • Set the Position property of two Employee objects to “Manager”.
    • Set the Position property of the remaining Employee objects to “Developer”.
  5. Create a new Employee object. In the Employee Detail View, specify the Department property and expand the Manager lookup editor. Notice that it only shows the managers from the specified department.

    ASP.NET Core Blazor
    ASP.NET Core Blazor filtered lookup editor items
    Windows Forms
    Windows Forms filtered lookup editor items

Tip

You can use integrated XAF designers to implement the same behavior without code. For details, refer to the following article: How to: Implement Cascading Filtering for Lookup List Views.

Next Lesson

Create a Calculated Property

See Also