diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs index 5233f2accc..ad082c3fb0 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs @@ -13,6 +13,9 @@ namespace Volo.Abp.Domain.Entities /// public static class EntityHelper { + private static readonly ConcurrentDictionary CachedIdProperties = + new ConcurrentDictionary(); + public static bool IsEntity([NotNull] Type type) { return typeof(IEntity).IsAssignableFrom(type); @@ -98,33 +101,29 @@ namespace Volo.Abp.Domain.Entities return Expression.Lambda>(lambdaBody, lambdaParam); } - private static readonly ConcurrentDictionary CachedPropertyInfo = - new ConcurrentDictionary(); - public static void TrySetId( IEntity entity, Func idFactory, - bool checkForDisableGuidGenerationAttribute = false) + bool checkForDisableIdGenerationAttribute = false) { - var property = CachedPropertyInfo.GetOrAdd( - entity.GetType().FullName + checkForDisableGuidGenerationAttribute, () => + var property = CachedIdProperties.GetOrAdd( + $"{entity.GetType().FullName}-{checkForDisableIdGenerationAttribute}", () => { - var entityType = entity.GetType(); - var idProperty = entityType.GetProperties() - .Where(x => x.GetSetMethod(true) != null) - .FirstOrDefault(x => x.Name == nameof(entity.Id)); + var idProperty = entity + .GetType() + .GetProperties() + .FirstOrDefault(x => x.Name == nameof(entity.Id) && + x.GetSetMethod(true) != null); if (idProperty == null) { return null; } - if (checkForDisableGuidGenerationAttribute) + if (checkForDisableIdGenerationAttribute && + idProperty.IsDefined(typeof(DisableIdGenerationAttribute), true)) { - if (idProperty.IsDefined(typeof(DisableIdGenerationAttribute), true)) - { - return null; - } + return null; } return idProperty;