Skip to main content
A newer version of this page is available. .

Current Object Parameter in XPO Applications

  • 5 minutes to read

The eXpressApp Framework provides methods for filtering Lookup Property Editors’ List Views. The DataSourceCriteria attribute is applied to a business class’ reference property and used to filter List Views. The List View in the drop-down window of the property’s Lookup Property Editor is filtered according to the criteria passed as the attribute’s parameter. When defining a filtering criterion applied to an object’s reference property, it is often necessary to access the object’s properties in the filtering criterion. For this purpose, the eXpressApp Framework supplies the Current Object Parameter. This topic describes the purpose of the Current Object Parameter and demonstrates how to use it.

Important

In the example below, there are two persistent classes - Contact and Position. Both the Contact and Position classes have the Department property. The Contact class has the Position-type Position property. As this is a reference property, it is represented in a UI using the Lookup Property Editor by default. If you want to limit the positions displayed in the Lookup Property Editors’ drop-down List Views, apply the DataSourceCriteria attribute to the Contact‘s Position property and specify a filtering criterion. When using the regular criteria syntax, you can only compare the Position class’ properties to some predefined values in the filtering criterion and use Function Criteria Operators. To define a criterion which lists only the available positions in the Department to which the edited Contact is assigned to, a criterion based on the Contact object’s property values is required. In this instance, the Current Object Parameter should be used. The Current Object Parameter allows you to access object properties in a criterion applied to the object’s reference property.

In criteria, the ‘@This.‘ prefix which precedes the name of the required object property represents the Current Object Parameter. The following code snippet illustrates using the Current Object Parameter based on the described Contact-Position example:

public class Contact : BaseObject {
    public Contact(Session session) : base(session) { }

    public string Name {
        get { return GetPropertyValue<string>("Name"); }
        set { SetPropertyValue<string>("Name", value); }
    }

    [Association("Contact-Department")]
    public Department Department {
        get { return GetPropertyValue<Department>("Department"); }
        set { SetPropertyValue<Department>("Department", value); }
    }

    [DataSourceCriteria("Department = '@This.Department'")]
    public Position Position {
        get { return GetPropertyValue<Position>("Position"); }
        set { SetPropertyValue<Position>("Position", value); }
    }
}

public class Position : BaseObject {
    public Position(Session session) : base(session) { }

    public string Title {
        get { return GetPropertyValue<string>("Title"); }
        set { SetPropertyValue<string>("Title", value); }
    }

    [Association("Department-Position")]
    public Department Department {
        get { return GetPropertyValue<Department>("Department"); }
        set { SetPropertyValue<Department>("Department", value); }
    }
}

public class Department : BaseObject {
    public Department(Session session) : base(session) { }

    public string Title {
        get { return GetPropertyValue<string>("Title"); }
        set { SetPropertyValue<string>("Title", value); }
    }

    [Association("Contact-Department")]
    public XPCollection<Contact> Contacts {
        get { return GetCollection<Contact>("Contacts"); }
    }

    [Association("Department-Position")]
    public XPCollection<Position> Positions {
        get { return GetCollection<Position>("Positions"); }
    }
}

In the code snippet below, the Current Object Parameter is used in the DataSourceCriteria attribute applied to the Position property.

public class Contact : BaseObject {
    // ...
    [DataSourceCriteria("Department = '@This.Department'")]
    public Position Position {
        // ...
    }
    // ...
}

The attribute specifies that Lookup Property Editors representing the Contact class’s Position property should only list the available positions in the department in which the edited contact works.

The Current Object Parameter can be used in the following contexts:

When using the @This. prefix in DataSourceCriteria, note that the master object (for which the lookup editor is displayed) is referred to, even if the lookup displays a complex property. For instance, if the lookup property is Task.Project.Manager, then @This refers to Task and not to Project..

[TIP] You can see another Current Object Parameter example in the MySolution.Module | Business Objects | Contact.cs (Contact.vb) file of Main Demo shipped with XAF. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 18.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version of this demo is available online at https://demos.devexpress.com/XAF/MainDemo.. This example’s code is described in the Comprehensive Tutorial’s Implement Dependent Reference Properties article.

See Also