===================================================
This example is now obsolete. Refer to the following documentation articles for more details:
When and Why XPO Extends the Database Schema
How to: Filter Persistent Objects by Type
IsInstanceOfTypeFunction Class
IsExactTypeFunction Class
===================================================
Scenario
We have a Department object that has a collection of Employees. Employees can be either objects of the LocalEmployee or ForeignEmployee types - descendants of the EmployeeBase class.
Our goal is to filter out a collection of employees by their type in code. In addition, there should be a capability to easily determine the employee type if a collection of EmployeeBase records is shown in the UI, e.g., by having a computed string property that returns the actual object type name.
Solution
To filter by the type, employ the service ObjectType field (or ObjectType.TypeName) or built-in IsExactType, IsInstanceOfType criteria functions provided by XPO.
Take special note that you can use these means with the PersistentAliasAttribute for filtering on the server side (see the EntityType property within the EmployeeBase class).
Check out the attached sample for a complete implementation and unit tests for this functionality.
IMPORTANT NOTES
This sample requires NUnit Framework.
See Also:
Criteria Language Syntax
Simplified Criteria Syntax
UpCasting
Question Comments
Added By: Santiago Moscoso at: 3/15/2013 8:50:38 AM
Is it possible to filter at the database level?
Added By: Dennis (DevExpress Support) at: 12/30/2013 12:39:09 AMYes, you can already filter by these service fields on the server side.