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
-
PrincipalCommandBase<IReadOnlyCollection<TReadModel>>PrincipalQueryBase<IReadOnlyCollection<TReadModel>>CacheableQueryBase<IReadOnlyCollection<TReadModel>>EntitySelectQuery<TReadModel>
- Implements
-
IRequest<IReadOnlyCollection<TReadModel>>IEquatable<EntitySelectQuery<TReadModel>>
- 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
ClaimsPrincipalThe 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
ClaimsPrincipalThe ClaimsPrincipal representing the user executing the query.
filter
EntityFilterThe 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
ClaimsPrincipalThe ClaimsPrincipal representing the user executing the query.
filter
EntityFilterThe EntityFilter to create an EntitySelect from.
sort
EntitySortThe 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
ClaimsPrincipalThe ClaimsPrincipal representing the user executing the query.
filter
EntityFilterThe 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
ClaimsPrincipalThe ClaimsPrincipal representing the user executing the query.
select
EntitySelectThe 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
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()