All docs
V21.2
21.2
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.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET 5.0+

Filter Lookup Editor Data Source

  • 2 minutes to read

This lesson explains how to filter data displayed in a lookup editor. This editor is used in the Detail Views for reference properties and contains a list of objects of another related class.

Note

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

  • Inherit from the Business Class Library Class (XPO/EF core)
  • Implement Custom Business Classes and Reference Properties (XPO/EF core)
  • Implement Dependent Reference Properties (XPO/EF core)
  • Set a Many-to-Many Relationship (XPO/EF core)

Step-by-Step Instructions

  1. Specify a Many-to-Many relationship between the Position and Department classes. For more information, refer to the Set a Many-to-Many Relationship (XPO) lesson.

    [DefaultClassOptions]
    [System.ComponentModel.DefaultProperty(nameof(Title))]
     public class Department : BaseObject {
       //...
       [Association("Departments-Positions")]
       public XPCollection<Position> Positions {
          get { return GetCollection<Position>(nameof(Positions)); }
       }
    }
    
    [DefaultClassOptions]
    [System.ComponentModel.DefaultProperty(nameof(Title))]
    public class Position : BaseObject {
          //...
       [Association("Departments-Positions")]
       public XPCollection<Department> Departments {
          get { return GetCollection<Department>(nameof(Departments)); }
       }
    }
    
  2. In the MySolution.Module project, open the “Model.DesignedDiffs.xafml” file in the Model Editor. Navigate to the BOModel | MySolution.Module.BusinessObjects node. Expand the Contact child node and select the OwnMembers | Position child node.

    Set the node properties as follows:

    • Set the DataSourceProperty property to Department.Positions.
    • Set the DataSourcePropertyIsNullMode property to SelectAll.

    xaf ASP.NET Core Blazor filter lookup editor

  3. In the Contact class (BusinessObjects\Contact.cs), replace the Department property declaration with the following code:

    [Association("Department-Contacts", typeof(Department)), ImmediatePostData]
    public Department Department {
       get {return department;}
       set {
          SetPropertyValue(nameof(Department), ref department, value);
          // Clear Position and Manager properties if the Department has been changed.
          if(!IsLoading) {
             Position = null;
             if(Manager != null && Manager.Department != value) {
                Manager = null;
             }
          }
       }
    }
    
  4. Run the application. Specify the Positions property for Department objects. Invoke a Contact Detail View. The Position editor dropdown lists Positions assigned to the Department object:

    xaf ASP.NET Core Blazor filter lookup editor

     

    xaf ASP.NET Core Blazor filter lookup editor

Detailed Explanation

In step 2, you specify the following:

  • The Position lookup editor displays the Department.Positions collection.
  • The Position lookup editor displays all existing objects in the Contact.Position editor when the Department.Positions property is not specified.

Next Lesson

Format a Property Value

See Also