Refactor MetadataProvider to improve table metadata retrieval logic#81
Refactor MetadataProvider to improve table metadata retrieval logic#81
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the MetadataProvider class to improve performance by implementing lazy loading for table metadata. Instead of pre-loading all entity types when a context is first accessed, the code now only creates TableMetadata on-demand for the specific entity type being requested.
Key changes:
- Added
readonlymodifier to the_tablesPerContextfield for immutability - Replaced eager loading of all entity types with lazy, on-demand loading
- Simplified cache lookup logic by inverting the conditional check
- Improved error message to be more specific about missing entity types
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| throw new InvalidOperationException($"The type '{modelType.FullName}' is not part of the model for the current context."); | ||
| } | ||
|
|
||
| var provider = context.GetService<IBulkInsertProvider>(); |
There was a problem hiding this comment.
The IBulkInsertProvider service is retrieved inside the lock on every cache miss. Consider moving this retrieval outside the lock (after checking for cache miss but before the lock, or after the model type check) to reduce lock contention, as GetService<T>() is typically thread-safe.
# Conflicts: # src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/MetadataProvider.cs
No description provided.