File tree Expand file tree Collapse file tree
src/PhenX.EntityFrameworkCore.BulkInsert/Metadata Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ namespace PhenX.EntityFrameworkCore.BulkInsert.Metadata;
77
88internal sealed class MetadataProvider
99{
10- private Dictionary < Type , TableMetadata > ? _tables ;
10+ private Dictionary < Type , Dictionary < Type , TableMetadata > > _tablesPerContext = new ( ) ;
1111
1212 public TableMetadata GetTableInfo < T > ( DbContext context )
1313 {
@@ -23,26 +23,25 @@ public TableMetadata GetTableInfo<T>(DbContext context)
2323
2424 private Dictionary < Type , TableMetadata > GetTables ( DbContext context )
2525 {
26- if ( _tables != null )
26+ lock ( _tablesPerContext )
2727 {
28- return _tables ;
29- }
30-
31- lock ( this )
32- {
33- if ( _tables != null )
28+ var type = context . GetType ( ) ;
29+ if ( _tablesPerContext . TryGetValue ( context . GetType ( ) , out var tables ) )
3430 {
35- return _tables ;
31+ return tables ;
3632 }
3733
3834 var provider = context . GetService < IBulkInsertProvider > ( ) ;
3935
40- _tables =
36+ tables =
4137 context . Model . GetEntityTypes ( )
4238 . ToDictionary (
4339 x => x . ClrType ,
4440 x => new TableMetadata ( x , provider . SqlDialect ) ) ;
45- return _tables ;
41+
42+ _tablesPerContext [ type ] = tables ;
43+
44+ return tables ;
4645 }
4746 }
4847}
You can’t perform that action at this time.
0 commit comments