The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

How to: Filter Persistent Objects by Type

  • 2 min 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.


employees.Criteria = PersistentBase.Fields.ObjectType.TypeName == typeof(ForeignEmployee).FullName;
//or
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:


[PersistentAlias("ObjectType.TypeName")]
public string EntityType { 
    get { 
        return Convert.ToString(EvaluateAlias("EntityType"));
    }
}
See Also