CRUDServiceBaseTEntity, TKey, TInput, TFilterPrepareNewEntityAsync Method

预处理新实体。用于在添加实体时,按需对其进行一些额外的加工。

Definition

Namespace: QuickAdmin.Service.CRUD
Assembly: QuickAdmin.Net (in QuickAdmin.Net.dll) Version: 2.0.11
C#
protected virtual Task<IServiceResult<TEntity>> PrepareNewEntityAsync(
	TEntity entity,
	CancellationToken cancellationToken
)

Parameters

entity  TEntity
将要添加的实体。
cancellationToken  CancellationToken
用于取消操作的令牌。

Return Value

TaskIServiceResultTEntity
服务调用结果。若成功,其数据即为加工过后的 entity

Remarks

若是 ISnowflakeEntity 且主键 Id0,将把 Id 置为新生成的雪花 Id(调用 NextSnowflakeId(Type, string))。
若是 IEntityWithUUIDKey 且主键 Id 无值,将把 Id 置为 32 位 GUID,如:"0de178a59a694491b2a445ca794e7b59",由以下代码生成:
C#
Guid.NewGuid().ToString("N")
对于审计类实体,方法内将把 entityCreatorId 置为当前用户 Id, 把 CreatedTime 置为当前系统时间(取自 NowForEntity)。

当需要做更多操作时可重写此方法去实现。

See Also