Skip to main content
.NET Standard 2.0+

How to: Filter Persistent Objects by Type

  • 2 minutes to read

This topic describes how to filter persistent objects by their type.

ObjectType Field

To filter objects by type, you can use the ObjectType service field (see When and Why XPO Extends the Database Schema).

IsExactType and IsInstanceOfType Function Operators

Alternatively, you can use the IsExactType and IsInstanceOfType function operators (see Criteria Language Syntax).

Assume you have a collection of Employee objects. Employees can either be objects of the LocalEmployee or ForeignEmployee types:

public class LocalEmployee : Employee { /* ... */ }

public class ForeignEmployee : Employee { /* ... */ }

The following code snippet demonstrates how the employees collection can be filtered to contain only foreign employees. The criteria is built with the Simplified Criteria Syntax.

employees.Criteria = PersistentBase.Fields.ObjectType.TypeName == typeof(ForeignEmployee).FullName;
employees.Criteria = CriteriaOperator.Parse("IsExactType(This,?)", typeof(ForeignEmployee).FullName);

For details on the IsExactType and IsInstanceOfType operators, refer to the IsExactTypeFunction and IsInstanceOfTypeFunction class descriptions

Display the Object Type in UI

To display the type in UI, you can implement the following calculated property using the PersistentAliasAttribute:

public string EntityType { 
    get { 
        return Convert.ToString(EvaluateAlias(nameof(EntityType)));
See Also