Table of Contents

Class InsertUnkeyedEntityIntoKeyedDbSetCommandHandler<TCommand, TResponse, TDbContext, TKeyedEntity>

Namespace
Whipstaff.MediatR.EntityFrameworkCore
Assembly
Whipstaff.MediatR.EntityFrameworkCore.dll

Abstract class for inserting an unkeyed entity into a DbSet<TEntity>.

public abstract class InsertUnkeyedEntityIntoKeyedDbSetCommandHandler<TCommand, TResponse, TDbContext, TKeyedEntity> : ICommandHandler<TCommand, TResponse>, IRequestHandler<TCommand, TResponse> where TCommand : ICommand<TResponse> where TDbContext : DbContext where TKeyedEntity : class

Type Parameters

TCommand

The type for the CQRS command.

TResponse

The type for the CQRS response.

TDbContext

The type for the DbContext.

TKeyedEntity

The type for the entity in the DbSet we will save to.

Inheritance
InsertUnkeyedEntityIntoKeyedDbSetCommandHandler<TCommand, TResponse, TDbContext, TKeyedEntity>
Implements
ICommandHandler<TCommand, TResponse>
IRequestHandler<TCommand, TResponse>
Derived
Inherited Members

Constructors

InsertUnkeyedEntityIntoKeyedDbSetCommandHandler()

protected InsertUnkeyedEntityIntoKeyedDbSetCommandHandler()

Methods

GetDbContext()

Gets the DbContext for use in inserting a record.

protected abstract TDbContext GetDbContext()

Returns

TDbContext

EF Core database context.

GetDbSet(TDbContext)

Gets the target DbSet for inserting data.

protected abstract DbSet<TKeyedEntity> GetDbSet(TDbContext dbContext)

Parameters

dbContext TDbContext

EfCore database context to use.

Returns

DbSet<TKeyedEntity>

DbSet to insert data to.

GetDbSetEntityFromUnkeyedEntity(TCommand)

Gets a Keyed entity for inserting into the DbSet.

protected abstract TKeyedEntity GetDbSetEntityFromUnkeyedEntity(TCommand command)

Parameters

command TCommand

Command to convert.

Returns

TKeyedEntity

Keyed entity to insert.

GetResponse(TKeyedEntity, int)

Gets the response to return from the command.

protected abstract TResponse GetResponse(TKeyedEntity entityAdded, int saveChangesResult)

Parameters

entityAdded TKeyedEntity

The entity that was inserted into the DbSet.

saveChangesResult int

The count of records saved, should be 1 in most cases, unless you have relational keys being affected.

Returns

TResponse

Response to return out of the command.

Handle(TCommand, CancellationToken)

Handles a request

public Task<TResponse> Handle(TCommand request, CancellationToken cancellationToken)

Parameters

request TCommand

The request

cancellationToken CancellationToken

Cancellation token

Returns

Task<TResponse>

Response from the request