33using Microsoft . EntityFrameworkCore . Metadata ;
44using Microsoft . EntityFrameworkCore . Storage ;
55using System ;
6+ using System . Collections . Concurrent ;
67using System . Collections . Generic ;
78using System . Data ;
89using System . Linq ;
@@ -12,15 +13,12 @@ namespace EntityFrameworkCore.SqlServer.SimpleBulks.Extensions;
1213
1314public static class DbContextExtensions
1415{
15- static readonly object _lockPropertiesCache = new ( ) ;
16- static readonly object _lockTableInforCache = new ( ) ;
17-
18- private static readonly Dictionary < Type , IList < ColumnInfor > > _propertiesCache = [ ] ;
19- private static readonly Dictionary < Type , TableInfor > _tableInfoCache = [ ] ;
16+ private static readonly ConcurrentDictionary < Type , IList < ColumnInfor > > _propertiesCache = [ ] ;
17+ private static readonly ConcurrentDictionary < Type , TableInfor > _tableInfoCache = [ ] ;
2018
2119 public static TableInfor GetTableInfor ( this DbContext dbContext , Type type )
2220 {
23- return _tableInfoCache . GetOrSet ( _lockTableInforCache , type , ( ) =>
21+ return _tableInfoCache . GetOrAdd ( type , ( type ) =>
2422 {
2523 var entityType = dbContext . Model . FindEntityType ( type ) ;
2624
@@ -50,7 +48,7 @@ public static SqlTransaction GetCurrentSqlTransaction(this DbContext dbContext)
5048
5149 public static IList < ColumnInfor > GetProperties ( this DbContext dbContext , Type type )
5250 {
53- return _propertiesCache . GetOrSet ( _lockPropertiesCache , type , ( ) =>
51+ return _propertiesCache . GetOrAdd ( type , ( type ) =>
5452 {
5553 var typeProperties = type . GetProperties ( ) . Select ( x => new { x . Name , x . PropertyType } ) ;
5654 var entityProperties = dbContext . Model . FindEntityType ( type )
0 commit comments