Browse Source

Fix nondeterministic exception order in GetManyAsDictionaryAsync and fix doc return type description

pull/25090/head
maliming 7 months ago
parent
commit
43d3c60d79
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 2
      docs/en/framework/infrastructure/entity-cache.md
  2. 11
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs

2
docs/en/framework/infrastructure/entity-cache.md

@ -182,7 +182,7 @@ public class ProductAppService : ApplicationService, IProductAppService
### Dictionary-Based Batch Retrieval ### Dictionary-Based Batch Retrieval
`FindManyAsDictionaryAsync` and `GetManyAsDictionaryAsync` return a `Dictionary<TKey, TEntityCacheItem>` 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 ```csharp
public async Task<Dictionary<Guid, ProductDto?>> FindManyAsDictionaryAsync(List<Guid> ids) public async Task<Dictionary<Guid, ProductDto?>> FindManyAsDictionaryAsync(List<Guid> ids)

11
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs

@ -94,15 +94,16 @@ public abstract class EntityCacheBase<TEntity, TEntityCacheItem, TKey> :
public virtual async Task<Dictionary<TKey, TEntityCacheItem>> GetManyAsDictionaryAsync(IEnumerable<TKey> ids) public virtual async Task<Dictionary<TKey, TEntityCacheItem>> GetManyAsDictionaryAsync(IEnumerable<TKey> ids)
{ {
var cacheItemDict = await GetCacheItemDictionaryAsync(ids.Distinct().ToArray()); var distinctIds = ids.Distinct().ToArray();
var cacheItemDict = await GetCacheItemDictionaryAsync(distinctIds);
var result = new Dictionary<TKey, TEntityCacheItem>(); var result = new Dictionary<TKey, TEntityCacheItem>();
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<TEntity>(pair.Key); throw new EntityNotFoundException<TEntity>(id);
} }
result[pair.Key] = pair.Value; result[id] = item;
} }
return result; return result;
} }

Loading…
Cancel
Save