Table of Contents

Class EntitySelectQuery<TReadModel>

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

Represents a query for selecting entities based on an EntitySelect. The result of the query will be a collection of type TReadModel.

public record EntitySelectQuery<TReadModel> : CacheableQueryBase<IReadOnlyCollection<TReadModel>>, IRequest<IReadOnlyCollection<TReadModel>>, IRequest, IEquatable<PrincipalCommandBase<IReadOnlyCollection<TReadModel>>>, IEquatable<PrincipalQueryBase<IReadOnlyCollection<TReadModel>>>, ICacheResult, IEquatable<CacheableQueryBase<IReadOnlyCollection<TReadModel>>>, IEquatable<EntitySelectQuery<TReadModel>>

Type Parameters

TReadModel

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

Inheritance
EntitySelectQuery<TReadModel>
Implements
Inherited Members

Examples

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

var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
var filter = new EntityFilter
{
    Name = "Status",
    Operator = "eq",
    Value = "Active"
};
var sort = new EntitySort
{
    Name = "Name",
    Direction = "asc"
};
var query = new EntitySelectQuery<ProductReadModel>(principal, filter, sort);

// Send the query to the mediator instance
var result = await mediator.Send(query);
Console.WriteLine($"Retrieved {result?.Count} entities.");

Remarks

This query is typically used in a CQRS (Command Query Responsibility Segregation) pattern to retrieve a collection of entities based on filtering and sorting criteria defined in an EntitySelect.

Constructors

EntitySelectQuery(ClaimsPrincipal?)

Initializes a new instance of the EntitySelectQuery<TReadModel> class with a default EntitySelect.

public EntitySelectQuery(ClaimsPrincipal? principal)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the query.

EntitySelectQuery(ClaimsPrincipal?, EntityFilter)

Initializes a new instance of the EntitySelectQuery<TReadModel> class with a filter.

public EntitySelectQuery(ClaimsPrincipal? principal, EntityFilter filter)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the query.

filter EntityFilter

The EntityFilter to create an EntitySelect from.

EntitySelectQuery(ClaimsPrincipal?, EntityFilter, EntitySort)

Initializes a new instance of the EntitySelectQuery<TReadModel> class with a filter and a single sort expression.

public EntitySelectQuery(ClaimsPrincipal? principal, EntityFilter filter, EntitySort sort)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the query.

filter EntityFilter

The EntityFilter to create an EntitySelect from.

sort EntitySort

The EntitySort to create an EntitySelect from.

EntitySelectQuery(ClaimsPrincipal?, EntityFilter, IEnumerable<EntitySort>)

Initializes a new instance of the EntitySelectQuery<TReadModel> class with a filter and multiple sort expressions.

public EntitySelectQuery(ClaimsPrincipal? principal, EntityFilter filter, IEnumerable<EntitySort> sort)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the query.

filter EntityFilter

The EntityFilter to create an EntitySelect from.

sort IEnumerable<EntitySort>

The list of EntitySort to create an EntitySelect from.

EntitySelectQuery(ClaimsPrincipal?, EntitySelect?)

Initializes a new instance of the EntitySelectQuery<TReadModel> class with a custom EntitySelect.

[JsonConstructor]
public EntitySelectQuery(ClaimsPrincipal? principal, EntitySelect? select)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the query.

select EntitySelect

The EntitySelect defining the filter and sort criteria for the query.

Properties

Select

Gets the EntitySelect defining the filter and sort criteria for the query.

[JsonPropertyName("select")]
public EntitySelect Select { get; }

Property Value

EntitySelect

Methods

GetCacheKey()

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

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.