Skip to content

Enable JSON column support for EF Core 10 complex collections#119

Merged
renemadsen merged 4 commits intomasterfrom
copilot/add-tojson-support-for-json
Nov 17, 2025
Merged

Enable JSON column support for EF Core 10 complex collections#119
renemadsen merged 4 commits intomasterfrom
copilot/add-tojson-support-for-json

Conversation

Copy link

Copilot AI commented Nov 17, 2025

Description

EF Core 10 requires complex collections (collections of complex types) to be mapped to JSON columns. The provider was blocking all JSON-mapped entities with an error from EF Core 7 era.

Changes

Core Changes

  • MySqlModelValidator: Removed validation that blocked JSON-mapped entities. Now delegates to EF Core's base implementation which handles complex collection requirements
  • MySqlComplianceTest: Prepared complex JSON test bases for enabling (currently commented pending validation)

Documentation & Tests

  • Added ComplexCollectionJsonMySqlTest.cs demonstrating complex collection usage
  • Added docs/ComplexCollections.md documenting version requirements and configuration

Database Version Requirements

Database Minimum Version Feature
MySQL 5.7.8+ Native JSON type
MariaDB 10.2.4+ JSON functions

Tests use [SupportedServerVersionCondition("Json")] to skip on unsupported versions.

Example

public class School
{
    public int Id { get; set; }
    public List<Department> Departments { get; set; } // Complex collection
}

// Complex type (no key)
public class Department  
{
    public string Name { get; set; }
    public int Budget { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<School>()
        .ComplexProperty(e => e.Departments); // Maps to JSON column in EF Core 10
}

Notes

  • No breaking changes
  • Compliance tests prepared but not enabled pending database validation
  • Complex collection API syntax may need refinement based on EF Core 10 final specification
Original prompt

This section details on the original issue you should resolve

<issue_title>ToJson is missing</issue_title>
<issue_description>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.

Figure which versions of mysql/mariadb that supports JSON as a data type and only do the tests for versions that will support it and skip it for older ones.

Also check reference MySQL and MariaDB documentation, so the results are as expected.</issue_description>

<agent_instructions>it is .net core 10</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 17, 2025 15:24
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ToJson mapping for complex collection property Enable JSON column support for EF Core 10 complex collections Nov 17, 2025
Copilot AI requested a review from renemadsen November 17, 2025 15:34
@renemadsen renemadsen marked this pull request as ready for review November 17, 2025 15:42
@renemadsen renemadsen merged commit 8a425dc into master Nov 17, 2025
0 of 18 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.

ToJson is missing

2 participants