Class Service<TKey, TEntity, TModel, TFilter>
- Namespace
- Magicalizer.Domain.Services
- Assembly
- Magicalizer.dll
Service of models with a primary key of one property.
public class Service<TKey, TEntity, TModel, TFilter> : ServiceBase<TEntity, TModel, TFilter>, IService<TKey, TModel, TFilter>, IService<TModel, TFilter> where TEntity : class, IEntity, new() where TModel : class, IModel<TEntity> where TFilter : class, IFilter
Type Parameters
TKeyPrimary key type.
TEntityEntity type.
TModelModel type.
TFilterFilter type.
- Inheritance
-
ServiceBase<TEntity, TModel, TFilter>Service<TKey, TEntity, TModel, TFilter>
- Inherited Members
Constructors
Service(DbContext, IEnumerable<IQueryPrefilter<TEntity, TFilter>>?, IValidator<TModel>?)
Creates a service.
public Service(DbContext dbContext, IEnumerable<IQueryPrefilter<TEntity, TFilter>>? queryPrefilters = null, IValidator<TModel>? validator = null)
Parameters
dbContextDbContextDatabase context.
queryPrefiltersIEnumerable<IQueryPrefilter<TEntity, TFilter>>Query prefilters that apply initial restrictions to queries.
validatorIValidator<TModel>Model validator.
Methods
DeleteAsync(TKey, CancellationToken)
Deletes the model by the primary key.
public virtual Task DeleteAsync(TKey id, CancellationToken cancellationToken = default)
Parameters
idTKeyPrimary key value.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
Exceptions
- ModelNotFoundException
The model doesn't exist (or isn't available through the query prefilters).
- ModelInUseException
The database restricts the deletion of the model (e.g. other models reference it).
GetByIdAsync(TKey, IEnumerable<IInclusion<TModel>>?, CancellationToken)
Gets the model by the primary key.
public virtual Task<TModel?> GetByIdAsync(TKey id, IEnumerable<IInclusion<TModel>>? inclusions = null, CancellationToken cancellationToken = default)
Parameters
idTKeyPrimary key value.
inclusionsIEnumerable<IInclusion<TModel>>Inclusions to apply (property paths of related models).
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<TModel>
Model, or
nullif it doesn't exist.