66using Localization . AspNetCore . EntityFramework . Entities ;
77using Localization . AspNetCore . EntityFramework . Enums ;
88using Localization . AspNetCore . EntityFramework . Extensions ;
9- using Localization . AspNetCore . EntityFramework . Models ;
109using Localization . AspNetCore . EntityFramework . Settings ;
1110using Microsoft . AspNetCore . Builder ;
1211using Microsoft . EntityFrameworkCore ;
@@ -22,7 +21,7 @@ internal class LocalizerFactory<T> : IStringLocalizerFactory, ILocalizationManag
2221 private readonly LocalizerOptions _localizerSettings ;
2322 private readonly RequestLocalizationOptions _requestLocalizationSettings ;
2423 private readonly IServiceProvider _serviceProvider ;
25- private List < LocalizationModel > _cache = new List < LocalizationModel > ( ) ;
24+ private List < LocalizationResource > _cache = new List < LocalizationResource > ( ) ;
2625
2726 public LocalizerFactory ( IServiceProvider serviceProvider ,
2827 IOptions < LocalizerOptions > localizerOptions ,
@@ -47,15 +46,8 @@ public void ResetCache()
4746 using ( var scope = _serviceProvider . GetScopedService ( out T context ) )
4847 {
4948 _cache = context . Set < LocalizationResource > ( )
50- . SelectMany ( l => l . Translations )
51- . Select ( t => new LocalizationModel
52- {
53- Id = t . Resource . Id ,
54- ResourceId = t . ResourceId ,
55- ResourceKey = t . Resource . ResourceKey ,
56- Language = t . Language ,
57- Value = t . Value
58- } )
49+ . Include ( r=> r . Translations )
50+ . AsNoTracking ( )
5951 . ToList ( ) ;
6052 }
6153 }
@@ -80,7 +72,8 @@ public LocalizedString GetResource(string resourceKey)
8072 throw new ArgumentException ( nameof ( resourceKey ) ) ;
8173
8274 var values = _cache
83- . Where ( t => t . ResourceKey == resourceKey
75+ . SelectMany ( r=> r . Translations )
76+ . Where ( t => t . Resource . ResourceKey == resourceKey
8477 && t . Language == CurrentLanguage )
8578 . Select ( p => p . Value )
8679 . ToList ( ) ;
@@ -141,16 +134,9 @@ private void UpdateCache(string resourceKey)
141134 using ( var scope = _serviceProvider . GetScopedService ( out T context ) )
142135 {
143136 var values = context . Set < LocalizationResource > ( )
137+ . AsNoTracking ( )
138+ . Include ( r=> r . Translations )
144139 . Where ( r => r . ResourceKey == resourceKey )
145- . SelectMany ( l => l . Translations )
146- . Select ( t => new LocalizationModel
147- {
148- Id = t . Resource . Id ,
149- ResourceId = t . ResourceId ,
150- ResourceKey = t . Resource . ResourceKey ,
151- Language = t . Language ,
152- Value = t . Value
153- } )
154140 . ToList ( ) ;
155141
156142 _cache . Where ( m => m . ResourceKey == resourceKey )
0 commit comments