Table of Contents

Retrieving

Behavior

This event is triggered on the server before the data fetching query is called.

It is triggered when you call the following methods :

The rule is cancelable in order to be able to prevent entities from being fetched.

Warning

In the current version, the event is not triggered for the additional data fetched through navigation properties.

Arguments

You can find the details of the interface here

Name Type Description
Context IBusinessRuleContext Represents a key/value pair dictionary that is used to store custom data. You can find the details of the interface on this page
Skip int? The number of elements to skip.
Top int? The number of elements to return.
Key object? The key if it is the retrieving of a particular record.
Parameters IReadOnlyEntityViewParameters The query strings parameter collection. You can find the details of the interface on this page
Items IReadOnlyList Items that will still be sent to the client when the data fetching request is canceled.
WillTransform boolean A value indicating whether the data will be transformed (e.g. grouping).
Cancel boolean If set to true, the query will not be called. Items can still manually be returned using the SetItemSource or SetItems method.
Note

The context is shared between the Retrieving and Retrieved events. Any value added in the context during the Retrieving event is available during the Retrieved event.

Manually setting the retrieved items

When you decide to cancel the data fetching query, you can still manually fill the args.Items property with a list of entities you want to return to the client.

Note

args.Items is read-only, you must call args.SetItems or args.SetItemsSource to initialize it.
args.Cancel does not need to be manually set to true when calling these methods as they automatically cancel the event.

A common use case is to return an already available list of items without reading the database.

Sometimes you may need to aggregate additional data with the data retrieved from the database. The args.RetrieveItemsAsync method allows you to get the data that would normally be retrieved from the database. You can then customize the retrieved items and call the args.SetItems or args.SetItemSource methods to set the items returned by the rule.

Filtering retrieved items

It is possible to add filters to the query that will be executed to retrieve items from the database :

  • args.AppendFilter adds a filter based on the entity view properties
  • args.AppendEntityFilter adds a filter based on the entity properties

Filters are boolean conditions that are appended using an AND operator. They need to be translatable in SQL by Entity Framework (see this article).

Note

You can call these methods multiple times to add as many filters as needed.