Add IncludeGraph support for full object graph bulk insert#91
Add IncludeGraph support for full object graph bulk insert#91
Conversation
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive support for bulk inserting entity graphs with navigation properties, addressing issue #2. The implementation enables users to insert entire object graphs (entities with their related navigation properties) while maintaining the library's performance characteristics through topological sorting and efficient FK propagation.
Changes:
- Added
IncludeGraphoption with supporting configuration options (MaxGraphDepth,IncludeNavigations,ExcludeNavigations) - Implemented graph processing infrastructure including metadata analysis, entity collection with cycle detection, and multi-table orchestration
- Added comprehensive test coverage across PostgreSQL, SQL Server, and SQLite providers with test entities for various relationship types
- Updated documentation to reflect new capabilities and mark the feature as complete in the roadmap
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| src/PhenX.EntityFrameworkCore.BulkInsert/Options/BulkInsertOptions.cs | Added four new options for graph insert configuration |
| src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/NavigationMetadata.cs | Navigation property metadata extraction and FK relationship analysis |
| src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/GraphMetadata.cs | Entity graph analysis and topological sorting for insertion order |
| src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphEntityCollector.cs | Graph traversal with cycle detection and entity collection |
| src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs | Multi-table insertion orchestration with generated ID propagation |
| src/PhenX.EntityFrameworkCore.BulkInsert/Extensions/PublicExtensions.DbSet.cs | Integration point that routes to graph orchestrator when IncludeGraph is enabled |
| src/PhenX.EntityFrameworkCore.BulkInsert/Abstractions/IBulkInsertProvider.cs | Added SupportsOutputInsertedIds property for provider capability detection |
| src/PhenX.EntityFrameworkCore.BulkInsert/BulkInsertProviderUntyped.cs | Default implementation of SupportsOutputInsertedIds |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/Blog.cs | Test entity for one-to-many relationships |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/Post.cs | Test entity for one-to-many and many-to-many relationships |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/Tag.cs | Test entity for many-to-many relationships |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/BlogSettings.cs | Test entity for one-to-one relationships |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/Category.cs | Test entity for self-referencing hierarchical relationships |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestDbContext.cs | Configuration of relationship mappings for test entities |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Graph/GraphTestsBase.cs | Comprehensive test suite covering various graph scenarios |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Graph/GraphTestsPostgreSql.cs | PostgreSQL-specific test runner |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Graph/GraphTestsSqlServer.cs | SQL Server-specific test runner |
| tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Graph/GraphTestsSqlite.cs | SQLite-specific test runner |
| docs/graph-insert.md | Comprehensive documentation of the graph insert feature |
| docs/documentation.md | Option documentation for the new graph insert options |
| docs/limitations.md | Updated to indicate navigation properties are now supported |
| README.md | Usage examples and roadmap update |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Graph/GraphTestsBase.cs
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Outdated
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Outdated
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Extensions/PublicExtensions.DbSet.cs
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Outdated
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Outdated
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Outdated
Show resolved
Hide resolved
tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Graph/GraphTestsBase.cs
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/GraphMetadata.cs
Outdated
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
|
@copilot add tests to ensure that inserted entities are linked to there original objects (with generated primary keys or not) |
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Added 3 new tests in commit 8e4dfe6:
|
|
@copilot Update the benchmark project to test include graph option. Do not write a new benchmark, only a boolean property that I can change to true if I want to benchmark Include graph insertion. When set to false (the default) the benchmark should run exactly the same way as it does now |
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Added |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Graph/GraphTestsBase.cs
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Outdated
Show resolved
Hide resolved
|
@copilot implement the suggestions provided in the latest review |
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Implemented the review suggestions in commit d927f1f:
|
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 33 out of 33 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Outdated
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Outdated
Show resolved
Hide resolved
tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Graph/GraphTestsBase.cs
Outdated
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Show resolved
Hide resolved
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.cs
Show resolved
Hide resolved
|
@copilot implement suggestions from latest review with these choices :
|
…clude join records in total count, filter keyless entities Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Implemented the requested changes in commit f21b3a8:
|
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Review feedback addressed:
TotalInsertedCountentityType.FindPrimaryKey() == nullcheck to filter out keyless entitieshasAnyGeneratedKeystohasAnyDatabaseGeneratedKeysfor clarityOriginal prompt
Implementation Plan: IncludeGraph Support for Full Object Graph Bulk Insert
1. Overview
Goal
Add the ability to bulk insert a full graph of objects (entities with their navigation properties/relationships) while maintaining the library's high-performance characteristics across all supported providers (PostgreSQL, SQL Server, SQLite, MySQL, Oracle).
This will fix issue #2
Current State
docs/limitations.mdand README roadmap)TableMetadataandColumnMetadataStudent ↔ Course(many-to-many) already exist in test entities but aren't bulk-insertable2. Changes to
BulkInsertOptions2.1 Add
IncludeGraphOption3. New Graph Processing Infrastructure
3.1 Create
GraphMetadataClassLocation:
src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/GraphMetadata.csPurpose: Analyze EF Core's
IEntityTypeto extract navigation property metadata, FK relationships, and dependency order.3.2 Create
NavigationMetadataClassLocation:
src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/NavigationMetadata.cs3.3 Create
GraphEntityCollectorClassLocation:
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphEntityCollector.csPurpose: Walk the object graph, collect all entities by type, and detect cycles.
3.4 Create
GraphBulkInsertOrchestratorClassLocation:
src/PhenX.EntityFrameworkCore.BulkInsert/Graph/GraphBulkInsertOrchestrator.csPurpose: Coordinate multi-table insertions with FK propagation.