Add ToJson() configuration for complex collections in EF Core 10#123
Add ToJson() configuration for complex collections in EF Core 10#123renemadsen merged 5 commits intomasterfrom
Conversation
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
|
@copilot We have these json errors: Error: System.InvalidOperationException : The store type 'null' specified for JSON column 'Activities' in table 'FieldPubWithCollections' is not supported by the current provider. JSON columns require a provider-specific JSON store type. Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_readonly_structs(state: Deleted, async: True) [1 ms] |
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
|
@copilot This file is also affected with tojson issue: Error: System.InvalidOperationException : The complex collection property 'School.Departments' must be mapped to a JSON column. Use 'ToJson()' to configure this complex collection as mapped to a JSON column. Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.PropertyValuesMySqlTest.Store_values_can_be_copied_into_a_non_generic_cloned_dictionary [1 ms] |
…lTest Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Fixed in 6a63f2a. Added |
|
@copilot That gave us these errors related to JSON: Error: System.InvalidOperationException : The store type 'json' specified for JSON column 'Activities' in table 'FieldPubWithCollections' is not supported by the current provider. JSON columns require a provider-specific JSON store type. Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_readonly_structs(state: Modified, async: False) [1 ms] Error: System.InvalidOperationException : The store type 'json' specified for JSON column 'Activities' in table 'FieldPubWithCollections' is not supported by the current provider. JSON columns require a provider-specific JSON store type. Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_readonly_structs(state: Added, async: False) [1 ms] Error: System.InvalidOperationException : The store type 'json' specified for JSON column 'Activities' in table 'FieldPubWithCollections' is not supported by the current provider. JSON columns require a provider-specific JSON store type. Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_readonly_structs(state: Modified, async: True) [1 ms] |
…ions Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Fixed in 81e3915. Removed |
Fix ToJson configuration for complex collection properties in EF Core 10
Summary
Added
.ToJson()configuration for complex collection properties across multiple test files to comply with EF Core 10 requirements. Complex collections must be explicitly mapped to JSON columns using.ToJson()without explicit column type specification.Changes Completed
.ToJson()configurations in ComplexTypesTrackingMySqlTest for 7 entity types.ToJson()configuration in ComplexCollectionJsonMySqlTestOnModelCreatingoverride in PropertyValuesMySqlTest to configure School.Departments.HasColumnType("json")as it's not supported when chained with.ToJson()for complex collectionsFiles Modified
test/EFCore.MySql.FunctionalTests/ComplexTypesTrackingMySqlTest.cs
.ToJson()configuration to 7 entity types with complex collections.ComplexCollection(e => e.Activities, b => b.ToJson())test/EFCore.MySql.FunctionalTests/ComplexCollectionJsonMySqlTest.cs
ComplexProperty()→ComplexCollection().ToJson().ComplexCollection(e => e.Departments).ToJson()test/EFCore.MySql.FunctionalTests/PropertyValuesMySqlTest.cs (NEW)
OnModelCreatingoverride in PropertyValuesMySqlFixture.ComplexCollection(e => e.Departments, b => b.ToJson())Technical Details
In EF Core 10, complex collections (collections of complex types) must be explicitly mapped to JSON columns using
.ToJson(). The configuration should not include.HasColumnType()when used with complex collections, as the provider determines the appropriate column type automatically.This matches the pattern from EF Core's base relational tests (
ComplexTypesTrackingRelationalTestBase.cs) which use.ToJson()without explicit column type specification.Original prompt
This section details on the original issue you should resolve
<issue_title>Fix more ToJson issues</issue_title>
<issue_description>```
Error: System.InvalidOperationException : The complex collection property 'FieldPubWithCollections.Activities' must be mapped to a JSON column. Use 'ToJson()' to configure this complex collection as mapped to a JSON column.
Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_readonly_structs(state: Modified, async: False) [1 ms]
Error Message:
System.InvalidOperationException : The complex collection property 'FieldPubWithCollections.Activities' must be mapped to a JSON column. Use 'ToJson()' to configure this complex collection as mapped to a JSON column.
Stack Trace:
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.ValidatePropertyMapping(IConventionComplexProperty complexProperty, IDiagnosticsLogger
1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IConventionTypeBase structuralType, IConventionModel model, IDiagnosticsLogger1 logger)at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IModel model, IDiagnosticsLogger
1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger)at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger
1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger1 validationLogger)at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
at Microsoft.EntityFrameworkCore.DbContext.get_Model()
at Microsoft.EntityFrameworkCore.DbContext.DisposeSync(Boolean leaseActive, Boolean contextShouldBeDisposed)
at Microsoft.EntityFrameworkCore.DbContext.DisposeAsync()
at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities.MySqlTestStore.InitializeAsync(Func
1 createContext, Func2 seed, Func2 clean) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/TestUtilities/MySqlTestStore.cs:line 158 at Microsoft.EntityFrameworkCore.TestUtilities.TestStore.<>c__DisplayClass13_0.<<InitializeAsync>b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.EntityFrameworkCore.TestUtilities.TestStoreIndex.CreateSharedAsync(String name, Func1 initializeDatabase)at Microsoft.EntityFrameworkCore.TestUtilities.TestStore.InitializeAsync(IServiceProvider serviceProvider, Func
1 createContext, Func2 seed, Func2 clean) at Microsoft.EntityFrameworkCore.TestUtilities.RelationalTestStore.InitializeAsync(IServiceProvider serviceProvider, Func1 createContext, Func2 seed, Func2 clean)at Microsoft.EntityFrameworkCore.SharedStoreFixtureBase`1.InitializeAsync()
[xUnit.net 00:00:15.58] Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_readonly_structs(state: Deleted, async: True) [FAIL]
[xUnit.net 00:00:15.58] Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_readonly_structs(state: Unchanged, async: True) [FAIL]
[xUnit.net 00:00:15.60] Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_read_original_values_for_properties_of_structs(trackFromQuery: True) [FAIL]
[xUnit.net 00:00:15.61] Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_read_original_values_for_properties_of_structs(trackFromQuery: False) [FAIL]
[xUnit.net 00:00:15.62] Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_record_objects_with_fields(state: Unchanged, async: False) [FAIL]
[xUnit.net 00:00:15.62] Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_record_objects_with_fields(state: Deleted, async: False) [FAIL]
[xUnit.net 00:00:15.63] Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_record_objects_with_fields(state: Added, async: True) [FAIL]
[xUnit.net 00:00:15.63] Pomelo.EntityFrameworkCore.MySql.FunctionalTests.ComplexTypesTrackingMySqlTest.Can_track_entity_with_complex_record_objects_with_fields(state: Added, async: False) [FAIL]
[xUnit.net ...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.