diff --git a/docs/en/framework/infrastructure/entity-cache.md b/docs/en/framework/infrastructure/entity-cache.md index e7540eec19..aed1f33c6e 100644 --- a/docs/en/framework/infrastructure/entity-cache.md +++ b/docs/en/framework/infrastructure/entity-cache.md @@ -182,7 +182,7 @@ public class ProductAppService : ApplicationService, IProductAppService ### Dictionary-Based Batch Retrieval -`FindManyAsDictionaryAsync` and `GetManyAsDictionaryAsync` return a `Dictionary` keyed by entity ID, which is convenient when you need fast lookup by ID: +`FindManyAsDictionaryAsync` and `GetManyAsDictionaryAsync` return results as a dictionary keyed by entity ID, which is convenient when you need fast lookup by ID: ```csharp public async Task> FindManyAsDictionaryAsync(List ids) diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs index 5ba2c047c0..826984a965 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs @@ -94,15 +94,16 @@ public abstract class EntityCacheBase : public virtual async Task> GetManyAsDictionaryAsync(IEnumerable ids) { - var cacheItemDict = await GetCacheItemDictionaryAsync(ids.Distinct().ToArray()); + var distinctIds = ids.Distinct().ToArray(); + var cacheItemDict = await GetCacheItemDictionaryAsync(distinctIds); var result = new Dictionary(); - foreach (var pair in cacheItemDict) + foreach (var id in distinctIds) { - if (pair.Value == null) + if (!cacheItemDict.TryGetValue(id, out var item) || item == null) { - throw new EntityNotFoundException(pair.Key); + throw new EntityNotFoundException(id); } - result[pair.Key] = pair.Value; + result[id] = item; } return result; }