Table of Contents

Class EntityPagedQuery<TReadModel>

Namespace
Arbiter.CommandQuery.Queries
Assembly
Arbiter.CommandQuery.dll

Represents a query for retrieving paged entities based on an EntityQuery. The result of the query will be of type EntityPagedResult<TReadModel>.

public record EntityPagedQuery<TReadModel> : CacheableQueryBase<EntityPagedResult<TReadModel>>, IRequest<EntityPagedResult<TReadModel>>, IRequest, IEquatable<PrincipalCommandBase<EntityPagedResult<TReadModel>>>, IEquatable<PrincipalQueryBase<EntityPagedResult<TReadModel>>>, ICacheResult, IEquatable<CacheableQueryBase<EntityPagedResult<TReadModel>>>, IEquatable<EntityPagedQuery<TReadModel>>

Type Parameters

TReadModel

The type of the read model returned as the result of the query.

Inheritance
EntityPagedQuery<TReadModel>
Implements
Inherited Members

Examples

The following example demonstrates how to use the EntityPagedQuery<TReadModel>:

var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
var entityQuery = new EntityQuery
{
    Filter = new EntityFilter { Name = "Status", Operator = "eq", Value = "Active" },
    Sort = new List<EntitySort> { new EntitySort { Name = "Name", Direction = "asc" } },
    Page = 1,
    PageSize = 20
};

var query = new EntityPagedQuery<ProductReadModel>(principal, entityQuery);

// Send the query to the mediator instance
var result = await mediator.Send(query);
Console.WriteLine($"Total Results: {result?.Total}");

Remarks

This query is typically used in a CQRS (Command Query Responsibility Segregation) pattern to retrieve entities in a paginated format. The EntityQuery allows filtering, sorting, and pagination criteria to be specified.

Constructors

EntityPagedQuery(ClaimsPrincipal?, EntityQuery?)

Initializes a new instance of the EntityPagedQuery<TReadModel> class.

public EntityPagedQuery(ClaimsPrincipal? principal, EntityQuery? query)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the query.

query EntityQuery

The EntityQuery defining the filter, sort, and pagination criteria for the query.

Properties

Query

Gets the EntityQuery defining the filter, sort, and pagination criteria for the query.

[JsonPropertyName("query")]
public EntityQuery Query { get; }

Property Value

EntityQuery

Methods

GetCacheKey()

Generates a cache key for the query based on the EntityQuery.

public override string GetCacheKey()

Returns

string

A string representing the cache key for the query.

GetCacheTag()

Gets the cache tag associated with the TReadModel.

public override string? GetCacheTag()

Returns

string

The cache tag for the TReadModel, or null if no tag is available.