Skip to content

Commit 166e601

Browse files
committed
Use a ConcurrentDictionary to store DisplayName values as they could be added after the model is built.
Fixes #12713
1 parent 6b4f643 commit 166e601

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/EFCore/Metadata/Internal/Model.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Concurrent;
56
using System.Collections.Generic;
67
using System.Diagnostics;
78
using System.Linq;
@@ -23,8 +24,8 @@ public class Model : ConventionalAnnotatable, IMutableModel
2324
private readonly SortedDictionary<string, EntityType> _entityTypes
2425
= new SortedDictionary<string, EntityType>();
2526

26-
private readonly Dictionary<Type, string> _clrTypeNameMap
27-
= new Dictionary<Type, string>();
27+
private readonly ConcurrentDictionary<Type, string> _clrTypeNameMap
28+
= new ConcurrentDictionary<Type, string>();
2829

2930
private readonly SortedDictionary<string, SortedSet<EntityType>> _entityTypesWithDefiningNavigation
3031
= new SortedDictionary<string, SortedSet<EntityType>>();
@@ -349,15 +350,7 @@ public virtual EntityType AddEntityType(
349350
/// directly from your code. This API may change or be removed in future releases.
350351
/// </summary>
351352
public virtual string GetDisplayName(Type type)
352-
{
353-
if (!_clrTypeNameMap.TryGetValue(type, out var name))
354-
{
355-
name = type.DisplayName();
356-
_clrTypeNameMap[type] = name;
357-
}
358-
359-
return name;
360-
}
353+
=> _clrTypeNameMap.GetOrAdd(type, t => t.DisplayName());
361354

362355
/// <summary>
363356
/// This API supports the Entity Framework Core infrastructure and is not intended to be used

0 commit comments

Comments
 (0)