Skip to content

Commit

Permalink
Use a ConcurrentDictionary to store DisplayName values as they could …
Browse files Browse the repository at this point in the history
…be added after the model is built.

Fixes #12713
  • Loading branch information
AndriySvyryd committed Aug 6, 2018
1 parent 6b4f643 commit 166e601
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/EFCore/Metadata/Internal/Model.cs
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand All @@ -23,8 +24,8 @@ public class Model : ConventionalAnnotatable, IMutableModel
private readonly SortedDictionary<string, EntityType> _entityTypes
= new SortedDictionary<string, EntityType>();

private readonly Dictionary<Type, string> _clrTypeNameMap
= new Dictionary<Type, string>();
private readonly ConcurrentDictionary<Type, string> _clrTypeNameMap
= new ConcurrentDictionary<Type, string>();

private readonly SortedDictionary<string, SortedSet<EntityType>> _entityTypesWithDefiningNavigation
= new SortedDictionary<string, SortedSet<EntityType>>();
Expand Down Expand Up @@ -349,15 +350,7 @@ public virtual EntityType RemoveEntityType([CanBeNull] EntityType entityType)
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GetDisplayName(Type type)
{
if (!_clrTypeNameMap.TryGetValue(type, out var name))
{
name = type.DisplayName();
_clrTypeNameMap[type] = name;
}

return name;
}
=> _clrTypeNameMap.GetOrAdd(type, t => t.DisplayName());

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

0 comments on commit 166e601

Please sign in to comment.