Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to filter persistent objects against their type

$
0
0

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.
Refer to the How to: Filter Persistent Objects by Type and When and Why XPO Extends the Database Schema help articles for more details.

IMPORTANT NOTES
This sample requires NUnit Framework.

See Also:
Criteria Language Syntax
Simplified Criteria Syntax
UpCasting
K18193

Example Comments

Added By: Santiago Moscoso at: 3/15/2013 11:50:38 AM    

Is it possible to filter at the database level?

Added By: Dennis (DevExpress Support) at: 12/30/2013 3:39:09 AM    

Yes, you can already filter by these service fields on the server side.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>