Skip to content

Add ToJson() configuration for complex collections in EF Core 10#123

Merged
renemadsen merged 5 commits intomasterfrom
copilot/fix-tojson-issues
Nov 18, 2025
Merged

Add ToJson() configuration for complex collections in EF Core 10#123
renemadsen merged 5 commits intomasterfrom
copilot/fix-tojson-issues

Conversation

Copy link

Copilot AI commented Nov 17, 2025

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

  • Analyzed error: "The complex collection property 'FieldPubWithCollections.Activities' must be mapped to a JSON column"
  • Added .ToJson() configurations in ComplexTypesTrackingMySqlTest for 7 entity types
  • Added .ToJson() configuration in ComplexCollectionJsonMySqlTest
  • Added OnModelCreating override in PropertyValuesMySqlTest to configure School.Departments
  • Resolved column type specification issue: removed .HasColumnType("json") as it's not supported when chained with .ToJson() for complex collections
  • Build verification successful

Files Modified

  1. test/EFCore.MySql.FunctionalTests/ComplexTypesTrackingMySqlTest.cs

    • Added .ToJson() configuration to 7 entity types with complex collections
    • Pattern: .ComplexCollection(e => e.Activities, b => b.ToJson())
  2. test/EFCore.MySql.FunctionalTests/ComplexCollectionJsonMySqlTest.cs

    • Fixed incorrect use of ComplexProperty()ComplexCollection().ToJson()
    • Pattern: .ComplexCollection(e => e.Departments).ToJson()
  3. test/EFCore.MySql.FunctionalTests/PropertyValuesMySqlTest.cs (NEW)

    • Added OnModelCreating override in PropertyValuesMySqlFixture
    • Configured School entity: .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, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IConventionTypeBase structuralType, IConventionModel model, IDiagnosticsLogger1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger1 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(Func1 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, Func1 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.

Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ToJson mapping issues for complex collections Add ToJson() configuration for complex collections in EF Core 10 Nov 17, 2025
Copilot AI requested a review from renemadsen November 17, 2025 17:38
@renemadsen
Copy link
Member

@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]
Error Message:
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.
Stack Trace:
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateContainerColumn[TColumnMappingBase](TableBase tableBase, String containerColumnName, String containerColumnType, ITypeBase mappedType, IRelationalTypeMappingSource relationalTypeMappingSource, Func5 createColumn) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateTableMapping(IRelationalTypeMappingSource relationalTypeMappingSource, ITypeBase typeBase, ITypeBase mappedType, StoreObjectIdentifier mappedTable, RelationalModel databaseModel, List1 tableMappings, Nullable1 includesDerivedTypes, Nullable1 isSplitEntityTypePrincipal)
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateTableMapping(IRelationalTypeMappingSource relationalTypeMappingSource, ITypeBase typeBase, ITypeBase mappedType, StoreObjectIdentifier mappedTable, RelationalModel databaseModel, List1 tableMappings, Nullable1 includesDerivedTypes, Nullable1 isSplitEntityTypePrincipal) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.AddTables(RelationalModel databaseModel, IEntityType entityType, IRelationalTypeMappingSource relationalTypeMappingSource) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, IRelationalTypeMappingSource relationalTypeMappingSource, Boolean designTime) at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.<>c__DisplayClass4_0.<InitializeModel>b__0() at Microsoft.EntityFrameworkCore.RelationalModelExtensions.<>c.<GetRelationalModel>b__4_0(Func1 f)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.<>c__302.<GetOrAddRuntimeAnnotationValue>b__30_0(String n, ValueTuple3 t)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd[TArg](TKey key, Func3 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.GetOrAddRuntimeAnnotationValue[TValue,TArg](String name, Func2 valueFactory, TArg factoryArgument) at Microsoft.EntityFrameworkCore.RelationalModelExtensions.GetRelationalModel(IModel model) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.GetCreateTablesCommands(MigrationsSqlGenerationOptions options) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.CreateTablesAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreatedAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_02.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func4 operation, Func4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func4 operation, Func4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken)
at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities.MySqlTestStore.InitializeAsync(Func1 createContext, Func2 seed, Func2 clean) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/TestUtilities/MySqlTestStore.cs:line 152 at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities.MySqlTestStore.InitializeAsync(Func1 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.<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, Func1 createContext, Func2 seed, Func2 clean)
at Microsoft.EntityFrameworkCore.TestUtilities.RelationalTestStore.InitializeAsync(IServiceProvider serviceProvider, Func1 createContext, Func2 seed, Func2 clean) at Microsoft.EntityFrameworkCore.SharedStoreFixtureBase1.InitializeAsync()

Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 17, 2025

@copilot We have these json errors:

...

Fixed in bc2aac2. Added .HasColumnType("json") to all .ToJson() configurations. MySQL requires explicit JSON column type specification - the base EF Core relational tests don't specify it because different providers use different store types.

@renemadsen
Copy link
Member

@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]
Error Message:
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.
Stack Trace:
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.ValidatePropertyMapping(IConventionComplexProperty complexProperty, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IConventionTypeBase structuralType, IConventionModel model, IDiagnosticsLogger1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger1 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(Func1 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, Func1 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()

…lTest

Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 18, 2025

@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()' t...

Fixed in 6a63f2a. Added OnModelCreating override to PropertyValuesMySqlFixture to configure the School.Departments complex collection with .ToJson().HasColumnType("json").

@renemadsen
Copy link
Member

@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 Message:
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.
Stack Trace:
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateContainerColumn[TColumnMappingBase](TableBase tableBase, String containerColumnName, String containerColumnType, ITypeBase mappedType, IRelationalTypeMappingSource relationalTypeMappingSource, Func5 createColumn) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateTableMapping(IRelationalTypeMappingSource relationalTypeMappingSource, ITypeBase typeBase, ITypeBase mappedType, StoreObjectIdentifier mappedTable, RelationalModel databaseModel, List1 tableMappings, Nullable1 includesDerivedTypes, Nullable1 isSplitEntityTypePrincipal)
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateTableMapping(IRelationalTypeMappingSource relationalTypeMappingSource, ITypeBase typeBase, ITypeBase mappedType, StoreObjectIdentifier mappedTable, RelationalModel databaseModel, List1 tableMappings, Nullable1 includesDerivedTypes, Nullable1 isSplitEntityTypePrincipal) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.AddTables(RelationalModel databaseModel, IEntityType entityType, IRelationalTypeMappingSource relationalTypeMappingSource) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, IRelationalTypeMappingSource relationalTypeMappingSource, Boolean designTime) at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.<>c__DisplayClass4_0.<InitializeModel>b__0() at Microsoft.EntityFrameworkCore.RelationalModelExtensions.<>c.<GetRelationalModel>b__4_0(Func1 f)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.<>c__302.<GetOrAddRuntimeAnnotationValue>b__30_0(String n, ValueTuple3 t)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd[TArg](TKey key, Func3 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.GetOrAddRuntimeAnnotationValue[TValue,TArg](String name, Func2 valueFactory, TArg factoryArgument) at Microsoft.EntityFrameworkCore.RelationalModelExtensions.GetRelationalModel(IModel model) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.GetCreateTablesCommands(MigrationsSqlGenerationOptions options) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.CreateTablesAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreatedAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_02.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func4 operation, Func4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func4 operation, Func4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken)
at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities.MySqlTestStore.InitializeAsync(Func1 createContext, Func2 seed, Func2 clean) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/TestUtilities/MySqlTestStore.cs:line 152 at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities.MySqlTestStore.InitializeAsync(Func1 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.<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, Func1 createContext, Func2 seed, Func2 clean)
at Microsoft.EntityFrameworkCore.TestUtilities.RelationalTestStore.InitializeAsync(IServiceProvider serviceProvider, Func1 createContext, Func2 seed, Func2 clean) at Microsoft.EntityFrameworkCore.SharedStoreFixtureBase1.InitializeAsync()

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 Message:
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.
Stack Trace:
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateContainerColumn[TColumnMappingBase](TableBase tableBase, String containerColumnName, String containerColumnType, ITypeBase mappedType, IRelationalTypeMappingSource relationalTypeMappingSource, Func5 createColumn) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateTableMapping(IRelationalTypeMappingSource relationalTypeMappingSource, ITypeBase typeBase, ITypeBase mappedType, StoreObjectIdentifier mappedTable, RelationalModel databaseModel, List1 tableMappings, Nullable1 includesDerivedTypes, Nullable1 isSplitEntityTypePrincipal)
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateTableMapping(IRelationalTypeMappingSource relationalTypeMappingSource, ITypeBase typeBase, ITypeBase mappedType, StoreObjectIdentifier mappedTable, RelationalModel databaseModel, List1 tableMappings, Nullable1 includesDerivedTypes, Nullable1 isSplitEntityTypePrincipal) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.AddTables(RelationalModel databaseModel, IEntityType entityType, IRelationalTypeMappingSource relationalTypeMappingSource) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, IRelationalTypeMappingSource relationalTypeMappingSource, Boolean designTime) at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.<>c__DisplayClass4_0.<InitializeModel>b__0() at Microsoft.EntityFrameworkCore.RelationalModelExtensions.<>c.<GetRelationalModel>b__4_0(Func1 f)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.<>c__302.<GetOrAddRuntimeAnnotationValue>b__30_0(String n, ValueTuple3 t)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd[TArg](TKey key, Func3 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.GetOrAddRuntimeAnnotationValue[TValue,TArg](String name, Func2 valueFactory, TArg factoryArgument) at Microsoft.EntityFrameworkCore.RelationalModelExtensions.GetRelationalModel(IModel model) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.GetCreateTablesCommands(MigrationsSqlGenerationOptions options) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.CreateTablesAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreatedAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_02.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func4 operation, Func4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func4 operation, Func4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken)
at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities.MySqlTestStore.InitializeAsync(Func1 createContext, Func2 seed, Func2 clean) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/TestUtilities/MySqlTestStore.cs:line 152 at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities.MySqlTestStore.InitializeAsync(Func1 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.<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, Func1 createContext, Func2 seed, Func2 clean)
at Microsoft.EntityFrameworkCore.TestUtilities.RelationalTestStore.InitializeAsync(IServiceProvider serviceProvider, Func1 createContext, Func2 seed, Func2 clean) at Microsoft.EntityFrameworkCore.SharedStoreFixtureBase1.InitializeAsync()

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]
Error Message:
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.
Stack Trace:
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateContainerColumn[TColumnMappingBase](TableBase tableBase, String containerColumnName, String containerColumnType, ITypeBase mappedType, IRelationalTypeMappingSource relationalTypeMappingSource, Func5 createColumn) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateTableMapping(IRelationalTypeMappingSource relationalTypeMappingSource, ITypeBase typeBase, ITypeBase mappedType, StoreObjectIdentifier mappedTable, RelationalModel databaseModel, List1 tableMappings, Nullable1 includesDerivedTypes, Nullable1 isSplitEntityTypePrincipal)
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateTableMapping(IRelationalTypeMappingSource relationalTypeMappingSource, ITypeBase typeBase, ITypeBase mappedType, StoreObjectIdentifier mappedTable, RelationalModel databaseModel, List1 tableMappings, Nullable1 includesDerivedTypes, Nullable1 isSplitEntityTypePrincipal) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.AddTables(RelationalModel databaseModel, IEntityType entityType, IRelationalTypeMappingSource relationalTypeMappingSource) at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, IRelationalTypeMappingSource relationalTypeMappingSource, Boolean designTime) at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.<>c__DisplayClass4_0.<InitializeModel>b__0() at Microsoft.EntityFrameworkCore.RelationalModelExtensions.<>c.<GetRelationalModel>b__4_0(Func1 f)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.<>c__302.<GetOrAddRuntimeAnnotationValue>b__30_0(String n, ValueTuple3 t)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd[TArg](TKey key, Func3 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.GetOrAddRuntimeAnnotationValue[TValue,TArg](String name, Func2 valueFactory, TArg factoryArgument) at Microsoft.EntityFrameworkCore.RelationalModelExtensions.GetRelationalModel(IModel model) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.GetCreateTablesCommands(MigrationsSqlGenerationOptions options) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.CreateTablesAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreatedAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_02.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func4 operation, Func4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func4 operation, Func4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken)
at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities.MySqlTestStore.InitializeAsync(Func1 createContext, Func2 seed, Func2 clean) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/TestUtilities/MySqlTestStore.cs:line 152 at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities.MySqlTestStore.InitializeAsync(Func1 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.<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, Func1 createContext, Func2 seed, Func2 clean)
at Microsoft.EntityFrameworkCore.TestUtilities.RelationalTestStore.InitializeAsync(IServiceProvider serviceProvider, Func1 createContext, Func2 seed, Func2 clean) at Microsoft.EntityFrameworkCore.SharedStoreFixtureBase1.InitializeAsync()

…ions

Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 18, 2025

@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 su...

Fixed in 81e3915. Removed .HasColumnType("json") from all complex collection .ToJson() calls. The .HasColumnType() method is not supported when chaining with .ToJson() for complex collections - the provider should determine the column type automatically.

@renemadsen renemadsen marked this pull request as ready for review November 18, 2025 06:40
@renemadsen renemadsen merged commit f4f8c31 into master Nov 18, 2025
1 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix more ToJson issues

2 participants