Table of Contents

Class EntityIdentifierQuery<TKey, TReadModel>

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

Represents a query for retrieving a single entity identified by a specific key. The result of the query will be of type TReadModel.

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

Type Parameters

TKey

The type of the key used to identify the entity.

TReadModel

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

Inheritance
PrincipalQueryBase<TReadModel>
CacheableQueryBase<TReadModel>
EntityIdentifierQuery<TKey, TReadModel>
Implements
IRequest<TReadModel>
Inherited Members

Examples

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

var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "JohnDoe") }));
var query = new EntityIdentifierQuery<int, ProductReadModel>(principal, 123);

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

Remarks

This query is typically used in a CQRS (Command Query Responsibility Segregation) pattern to retrieve a single entity based on its unique identifier. It supports caching to optimize repeated queries for the same entity.

Constructors

EntityIdentifierQuery(ClaimsPrincipal?, TKey)

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

public EntityIdentifierQuery(ClaimsPrincipal? principal, TKey id)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the query.

id TKey

The identifier of the entity to retrieve.

Exceptions

ArgumentNullException

Thrown when id is null.

Properties

Id

Gets the identifier of the entity to retrieve.

[JsonPropertyName("id")]
public TKey Id { get; }

Property Value

TKey

The identifier of the entity to retrieve.

Methods

GetCacheKey()

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

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.