Table of Contents

Class EntityUpdateCommand<TKey, TUpdateModel, TReadModel>

Namespace
Arbiter.CommandQuery.Commands
Assembly
Arbiter.CommandQuery.dll

Represents a command to update an entity identified by a specific key using the provided update model. The result of the command will be of type TReadModel.

public record EntityUpdateCommand<TKey, TUpdateModel, TReadModel> : EntityModelCommand<TUpdateModel, TReadModel>, IRequest<TReadModel>, IRequest, IEquatable<PrincipalCommandBase<TReadModel>>, IEquatable<EntityModelCommand<TUpdateModel, TReadModel>>, ICacheExpire, IEquatable<EntityUpdateCommand<TKey, TUpdateModel, TReadModel>>

Type Parameters

TKey

The type of the key used to identify the entity.

TUpdateModel

The type of the update model containing the data for the update.

TReadModel

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

Inheritance
EntityModelCommand<TUpdateModel, TReadModel>
EntityUpdateCommand<TKey, TUpdateModel, TReadModel>
Implements
IRequest<TReadModel>
IEquatable<EntityModelCommand<TUpdateModel, TReadModel>>
IEquatable<EntityUpdateCommand<TKey, TUpdateModel, TReadModel>>
Inherited Members

Examples

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

var updateModel = new ProductUpdateModel
{
    Name = "Updated Product",
    Description = "Updated description of the product",
    Price = 29.99m
};

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

// Pass the command to a handler or mediator
var result = await mediator.Send(command);
Console.WriteLine($"Updated product name: {result?.Name}");

Remarks

This command is typically used in a CQRS (Command Query Responsibility Segregation) pattern to update an entity and return a read model representing the updated entity or a related result.

Constructors

EntityUpdateCommand(ClaimsPrincipal?, TKey, TUpdateModel)

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

public EntityUpdateCommand(ClaimsPrincipal? principal, TKey id, TUpdateModel model)

Parameters

principal ClaimsPrincipal

The ClaimsPrincipal representing the user executing the command.

id TKey

The identifier of the entity to update.

model TUpdateModel

The update model containing the data for the update.

Exceptions

ArgumentNullException

Thrown when id or model is null.

Properties

Id

Gets the identifier of the entity to update.

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

Property Value

TKey

The identifier of the entity to update.