diff --git a/src/Volo.Abp/Volo/Abp/Application/Services/CrudAppServiceBase.cs b/src/Volo.Abp/Volo/Abp/Application/Services/CrudAppServiceBase.cs index 555b2d46b3..3cdff642f1 100644 --- a/src/Volo.Abp/Volo/Abp/Application/Services/CrudAppServiceBase.cs +++ b/src/Volo.Abp/Volo/Abp/Application/Services/CrudAppServiceBase.cs @@ -115,15 +115,24 @@ namespace Volo.Abp.Application.Services protected virtual TEntity MapToEntity(TCreateInput createInput) { var entity = ObjectMapper.Map(createInput); + SetIdForGuids(entity); + return entity; + } - //Set ID for GUIDs + /// + /// Sets Id value for the entity if is . + /// It's used while creating a new entity. + /// + protected virtual void SetIdForGuids(TEntity entity) + { var entityWithGuidId = entity as IEntity; - if (entityWithGuidId != null && entityWithGuidId.Id == Guid.Empty) + + if (entityWithGuidId == null || entityWithGuidId.Id != Guid.Empty) { - entityWithGuidId.Id = GuidGenerator.Create(); + return; } - return entity; + entityWithGuidId.Id = GuidGenerator.Create(); } ///