Table of Contents

Interface IRetrievingRuleArguments<TEntityView>

Namespace
GroupeIsa.Neos.Application.Rules.EventRules
Assembly
GroupeIsa.Neos.Application.Abstractions.dll

Provides the functionalities of a retrieving rule arguments.

public interface IRetrievingRuleArguments<TEntityView> : IRetrievedRuleArguments<TEntityView>, IContextRuleArguments, ICancelableRuleArguments, IRuleArguments where TEntityView : IEntityView

Type Parameters

TEntityView

The entity view type.

Inherited Members

Properties

EntityType

Gets the type of the entity associated with the entity view, or null for an unbound entity view.

Type? EntityType { get; }

Property Value

Type

IsCountQuery

Gets a value indicating whether the query is a count query.

bool IsCountQuery { get; }

Property Value

bool

WillTransform

Gets a value indicating whether the data will be transformed (grouping or select).

bool WillTransform { get; }

Property Value

bool

Methods

AppendEntityFilter<TEntity>(Expression<Func<TEntity, bool>>)

Sets a filter based on the properties of the entity associated with the entity view.

void AppendEntityFilter<TEntity>(Expression<Func<TEntity, bool>> predicate) where TEntity : BusinessEntity

Parameters

predicate Expression<Func<TEntity, bool>>

A function to test each element for a condition.

Type Parameters

TEntity

Type of the entity of the entity associated with.

Remarks

This filter is ignored when using the SetItemsSource(IEnumerable<TEntityView>) method.

AppendFilter(Expression<Func<TEntityView, bool>>)

Sets a filter based on the properties of the entity view.

void AppendFilter(Expression<Func<TEntityView, bool>> predicate)

Parameters

predicate Expression<Func<TEntityView, bool>>

A function to test each element for a condition.

RetrieveCountAsync(Func<IQueryable<TEntityView>, IQueryable<TEntityView>>?, CancellationToken)

Retrieves the total number of entity view items, without loading the items themselves. The process launched is the standard retrieve process of the entity view except that the Retrieving/Retrieved events are not triggered and no pagination is applied.

Task<int> RetrieveCountAsync(Func<IQueryable<TEntityView>, IQueryable<TEntityView>>? queryCustomization, CancellationToken cancellationToken)

Parameters

queryCustomization Func<IQueryable<TEntityView>, IQueryable<TEntityView>>

Query customization.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<int>

The total number of items.

Examples

The following example shows how to call RetrieveCountAsync to obtain a count without loading every matching item.

int activeCustomerCount = await args.RetrieveCountAsync(q => q.Where(c => c.IsActive), cancellationToken);
_logger.LogInformation($"activeCustomerCount: {activeCustomerCount}");

RetrieveCountAsync(CancellationToken)

Retrieves the total number of entity view items, without loading the items themselves. The process launched is the standard retrieve process of the entity view except that the Retrieving/Retrieved events are not triggered and no pagination is applied.

Task<int> RetrieveCountAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

Task<int>

The total number of items.

Examples

The following example shows how to call RetrieveCountAsync to obtain a count without loading every matching item.

int activeCustomerCount = await args.RetrieveCountAsync(q => q.Where(c => c.IsActive), cancellationToken);
_logger.LogInformation($"activeCustomerCount: {activeCustomerCount}");

RetrieveItemsAsync()

Retrieves the entity view items. The process launched is the standard retrieve process of the entity view except that the Retrieving/Retrieved events are not triggered and no pagination is applied.

Task<TEntityView[]> RetrieveItemsAsync()

Returns

Task<TEntityView[]>

The retrieved items.

Examples

The following example shows how to call RetrieveItemsAsync to aggregate entity view customers with an external source.

IEnumerable<ICustomerView> externalCustomers = GetExternalCustomers();
IEnumerable<ICustomerView> internalCustomers = await args.RetrieveItemsAsync(q => q.Where(c => c.IsActive));
args.SetItemsSource(externalCustomers.Concat(internalCustomers));

RetrieveItemsAsync(Func<IQueryable<TEntityView>, IQueryable<TEntityView>>?)

Retrieves the entity view items. The process launched is the standard retrieve process of the entity view except that the Retrieving/Retrieved events are not triggered and no pagination is applied.

Task<TEntityView[]> RetrieveItemsAsync(Func<IQueryable<TEntityView>, IQueryable<TEntityView>>? queryCustomization)

Parameters

queryCustomization Func<IQueryable<TEntityView>, IQueryable<TEntityView>>

Query customization.

Returns

Task<TEntityView[]>

The retrieved items.

Examples

The following example shows how to call RetrieveItemsAsync to aggregate entity view customers with an external source.

IEnumerable<ICustomerView> externalCustomers = GetExternalCustomers();
IEnumerable<ICustomerView> internalCustomers = await args.RetrieveItemsAsync(q => q.Where(c => c.IsActive));
args.SetItemsSource(externalCustomers.Concat(internalCustomers));

RetrieveItemsAsync(Func<IQueryable<TEntityView>, IQueryable<TEntityView>>?, CancellationToken)

Retrieves the entity view items. The process launched is the standard retrieve process of the entity view except that the Retrieving/Retrieved events are not triggered and no pagination is applied.

Task<TEntityView[]> RetrieveItemsAsync(Func<IQueryable<TEntityView>, IQueryable<TEntityView>>? queryCustomization, CancellationToken cancellationToken)

Parameters

queryCustomization Func<IQueryable<TEntityView>, IQueryable<TEntityView>>

Query customization.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<TEntityView[]>

The retrieved items.

Examples

The following example shows how to call RetrieveItemsAsync to aggregate entity view customers with an external source.

IEnumerable<ICustomerView> externalCustomers = GetExternalCustomers();
IEnumerable<ICustomerView> internalCustomers = await args.RetrieveItemsAsync(q => q.Where(c => c.IsActive));
args.SetItemsSource(externalCustomers.Concat(internalCustomers));

RetrieveItemsAsync(CancellationToken)

Retrieves the entity view items. The process launched is the standard retrieve process of the entity view except that the Retrieving/Retrieved events are not triggered and no pagination is applied.

Task<TEntityView[]> RetrieveItemsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

Task<TEntityView[]>

The retrieved items.

Examples

The following example shows how to call RetrieveItemsAsync to aggregate entity view customers with an external source.

IEnumerable<ICustomerView> externalCustomers = GetExternalCustomers();
IEnumerable<ICustomerView> internalCustomers = await args.RetrieveItemsAsync(q => q.Where(c => c.IsActive));
args.SetItemsSource(externalCustomers.Concat(internalCustomers));

RetrievePagedItemsAsync(Func<IQueryable<TEntityView>, IQueryable<TEntityView>>?, CancellationToken)

Retrieves a page of entity view items together with the total number of matching items, in a single call. The process launched is the standard retrieve process of the entity view except that the Retrieving/Retrieved events are not triggered. Pagination (Skip and Top) is applied by this method itself: the query customization must contain filters and sorting only, not paging, so the same customization can be reused to compute the total.

Task<IPagedList<TEntityView>> RetrievePagedItemsAsync(Func<IQueryable<TEntityView>, IQueryable<TEntityView>>? queryCustomization, CancellationToken cancellationToken)

Parameters

queryCustomization Func<IQueryable<TEntityView>, IQueryable<TEntityView>>

Query customization. Must not apply Skip/Take, it is applied by this method.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<IPagedList<TEntityView>>

The page of items and the total number of matching items.

Examples

The following example shows how to call RetrievePagedItemsAsync to obtain a page of items and the total count in a single call.

// args.Skip and args.Top are applied internally: the query customization only needs filters and sorting.
IPagedList<ICustomerView> pagedCustomers = await args.RetrievePagedItemsAsync(q => q.Where(c => c.IsActive).OrderBy(c => c.Name), cancellationToken);
args.SetItems(pagedCustomers, pagedCustomers.TotalRecordCount);

Exceptions

InvalidOperationException

Skip or Top is not set.

RetrievePagedItemsAsync(CancellationToken)

Retrieves a page of entity view items together with the total number of matching items, in a single call. The process launched is the standard retrieve process of the entity view except that the Retrieving/Retrieved events are not triggered. Pagination (Skip and Top) is applied by this method itself: the query customization must contain filters and sorting only, not paging, so the same customization can be reused to compute the total.

Task<IPagedList<TEntityView>> RetrievePagedItemsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

Task<IPagedList<TEntityView>>

The page of items and the total number of matching items.

Examples

The following example shows how to call RetrievePagedItemsAsync to obtain a page of items and the total count in a single call.

// args.Skip and args.Top are applied internally: the query customization only needs filters and sorting.
IPagedList<ICustomerView> pagedCustomers = await args.RetrievePagedItemsAsync(q => q.Where(c => c.IsActive).OrderBy(c => c.Name), cancellationToken);
args.SetItems(pagedCustomers, pagedCustomers.TotalRecordCount);

Exceptions

InvalidOperationException

Skip or Top is not set.

SetCount(long)

Sets the count of the items and cancels the event when IsCountQuery is true.

void SetCount(long count)

Parameters

count long

The count.

Exceptions

InvalidOperationException

The method is called when IsCountQuery is false.

SetItems(IEnumerable<TEntityView>, int?)

Sets the items to retrieve and cancels the event.

void SetItems(IEnumerable<TEntityView> items, int? totalRecordCount = null)

Parameters

items IEnumerable<TEntityView>

Items.

totalRecordCount int?

Total record count.

Examples

The following example shows how to call SetItems to retrieve customers from a custom source.

_logger.LogInformation($"args.Skip: {args.Skip}");
_logger.LogInformation($"args.Top: {args.Top}");
ICustomerView[] customers = GetCustomers(args.Skip, args.Top);
int customerCount = GetCustomerCount();
_logger.LogInformation($"customers.Length: {customers.Length}");
_logger.LogInformation($"customerCount: {customerCount}");
args.SetItems(customers, customerCount);

// Log output: // args.Skip: 5 // args.Top: 10 // customers.Length: 10 // customerCount: 150

You can note that you don't have to set Cancel to true, the call to SetItems does it automatically.

When you use this method, you must provide a list for which you have already applied pagination, filters and sorting.

SetItems(IQueryable<TEntityView>)

Sets the items to retrieve and cancels the event.

[Obsolete("Use SetItemsSource")]
void SetItems(IQueryable<TEntityView> query)

Parameters

query IQueryable<TEntityView>

Query.

SetItemsSource(IEnumerable<TEntityView>)

Sets a source for the items to retrieve and cancels the event. Filters and sorts will be applied to this source.

void SetItemsSource(IEnumerable<TEntityView> source)

Parameters

source IEnumerable<TEntityView>

Source.

Examples

The following example shows how to call SetItemsSource to retrieve customers from a custom source.

_logger.LogInformation($"args.Skip: {args.Skip}");
_logger.LogInformation($"args.Top: {args.Top}");
IEnumerable<ICustomerView> source = GetCustomers();
_logger.LogInformation($"customerCount: {source.Count()}");
args.SetItemsSource(source);

// Log output: // args.Skip: 5 // args.Top: 10 // customerCount: 150

Note that you don't have to set Cancel to true, the call to SetItemsSource does it automatically.

When you use this method, you must provide a source without pagination. The query can contain filters but Filter will be applied in addition.