Table of Contents

Filter embedded collections in entity views

You can use CollectionFilter on an entity view collection property to keep only the items that match a condition.

This is useful when a parent entity view must expose multiple filtered views of the same collection, or when an embedded collection should only return relevant items.

When to use a collection filter

Use CollectionFilter when:

  • a collection is embedded in an entity view,
  • but the content of the embedded collection must be reduced.

Typical use cases include:

  • splitting one collection into several sub-collections based on a discriminator,
  • hiding child items that do not meet a business condition,
  • adapting the embedded collection to the current application context.

Requirements and limitations

CollectionFilter is only available on embedded collection properties of an entity view.

In practice, this means the property must:

  • have Type: Collection,
  • be bound to a collection through Source,
  • define a RelatedEntityViewName.

The filter applies to the items of the embedded collection, not to the root entity view result.

Basic example

The following entity view only keeps order details that contain notes:

- Name: Details
  Caption: Details
  CollectionFilter: e.Notes != null
  RelatedEntityViewName: RefColOrderDetailView
  Source: Details
  Type: Collection

With this configuration, the parent order is still returned, but its Details collection only contains items whose Notes property is not null.

Split one collection into multiple filtered collections

You can define multiple entity view properties that all point to the same source collection and apply a different CollectionFilter on each one.

- Name: ProductsInStock
  Caption: Product in stock
  CollectionFilter: e.InStock
  RelatedEntityViewName: ProductListView
  Source: Products
  Type: Collection
- Name: ProductsOutOfStock
  Caption: Product out of stock
  CollectionFilter: !e.InStock
  RelatedEntityViewName: ProductListView
  Source: Products
  Type: Collection

This pattern is useful when a UI view displays the same source collection in multiple sub-views.

For a complete walkthrough, see How to split an embedded collection via a discriminator.

Example with application context

The filter can also depend on application context values.

- Name: Accounts
  Caption: Accounts
  CollectionFilter: ApplicationContext.FindStringValue("UserAccountType") == null || ApplicationContext.GetStringValue("UserAccountType") == "Publisher"
  RelatedEntityViewName: UserAccountUserRoleView
  Source: Accounts
  Type: Collection

This allows the embedded collection to adapt to the current execution context while keeping a single entity view definition.

Relationship with filtering on nested properties

CollectionFilter and filtering on nested properties solve different problems:

  • CollectionFilter filters the content of an embedded collection returned inside a parent entity view item.
  • Filtering on nested properties allows the user to filter the root entity view results through the filter bar or quick search.

For example, filtering on OrderDetails.Product.ProductName affects which orders are returned. CollectionFilter affects which order details are present inside each returned order.

For more information about nested filtering, see Entity view properties.

See also