Skip to content

Commit 04f2131

Browse files
Fix provider.
1 parent e819906 commit 04f2131

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/MetadataProvider.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PhenX.EntityFrameworkCore.BulkInsert.Metadata;
77

88
internal 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
}

0 commit comments

Comments
 (0)