Table of Contents

Class EntityIdentifiersQuery<TKey, TReadModel>

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

Represents a query for retrieving multiple entities identified by a list of keys. The result of the query will be a collection of type TReadModel.

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

Type Parameters

TKey

The type of the keys used to identify the entities.

TReadModel

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

Inheritance
EntityIdentifiersQuery<TKey, TReadModel>
Implements
Inherited Members

Examples

The following example demonstrates how to use the EntityIdentifiersQuery<TKey, TReadModel>:

var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
var ids = new List<int> { 1, 2, 3 };
var query = new EntityIdentifiersQuery<int, ProductReadModel>(principal, ids);

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

Remarks

This query is typically used in a CQRS (Command Query Responsibility Segregation) pattern to retrieve multiple entities based on their unique identifiers. It supports caching to optimize repeated queries for the same set of entities.

Constructors

EntityIdentifiersQuery(ClaimsPrincipal?, IReadOnlyCollection<TKey>)

Initializes a new instance of the EntityIdentifiersQuery<TKey, TReadModel> class.

public EntityIdentifiersQuery(ClaimsPrincipal? principal, IReadOnlyCollection<TKey> ids)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the query.

ids IReadOnlyCollection<TKey>

The list of identifiers for the entities to retrieve.

Exceptions

ArgumentNullException

Thrown when ids is null.

Properties

Ids

Gets the list of identifiers for the entities to retrieve.

[JsonPropertyName("ids")]
public IReadOnlyCollection<TKey> Ids { get; }

Property Value

IReadOnlyCollection<TKey>

The list of identifiers for the entities to retrieve.

Methods

GetCacheKey()

Generates a cache key for the query based on the list of identifiers.

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.