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
Add the new
Managerproperty to theEmployeeclass:using DevExpress.ExpressApp.DC; //... public class Employee : BaseObject { //... public virtual Employee Manager { get; set; } }Apply the
DataSourcePropertyandDataSourceCriteriaattributes 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
DataSourcePropertyattribute accepts two parameters:dataSourcePropertyandmode.The
dataSourcePropertyparameter 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
modeparameter 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
DataSourcePropertyIsNullCriteriaparameter to specify criteria to filter the List View by the target property’s Lookup Property Editor.The
DataSourceCriteriaattribute restricts the Manager lookup editor items to specific objects. With the"Position.Title = 'Manager'"filter, the lookup editor displays only theEmployeeobjects whosePositionproperty value is"Manager".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”.
Create a new
Employeeobject. In the Employee Detail View, specify theDepartmentproperty and expand the Manager lookup editor. Notice that it only shows the managers from the specified department.- ASP.NET Core Blazor

- Windows Forms

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.