-
Couldn't load subscription status.
- Fork 3.3k
Description
Bug description
I've noticed a serialization/deserialization issue with complex properties in EF Core 10 RC2.
The issue only happens if I try to use a different Json property name for the complex collection of Rows.
If I remove the line
b.HasJsonPropertyName(nameof(DataTable.Rows).ToCamelCase());
It serializes in the database as 'Rows' and deserializes successfully on table fetch.
If I add the line again it successfully serializes as 'rows' but it wont deserialize (Rows equal null) on table fetch.
Btw note how the ConfigureComplexDataTable doesn't actually do anything except renaming the json properties. Would be ideal if EF Core team provides that functionality via configuration or if it serializes json in camelCase by default.
Your code
entity.ComplexProperty(e => e.DataTable)
.ConfigureComplexDataTable()
.IsRequired();
public static ComplexPropertyBuilder<DataTable> ConfigureComplexDataTable(this ComplexPropertyBuilder<DataTable> complexBuilder)
{
// Use JSON conversion for the entire DataTable object, this will map to a single column in the database
// of type nvarchar(max) or json if supported (compatibility mode for SQL Server and Azure SQL >= 170)
// By default the json keys will be in PascalCase, we will override them below to be in camelCase
complexBuilder.ToJson();
// Map properties to camelCase JSON keys, this is optional but recommended for consistency and JSON standards
// This is all this method does, the actual storage is handled by the ToJson() call above
complexBuilder.PrimitiveCollection(a => a.Headers)
.HasJsonPropertyName(nameof(DataTable.Headers).ToCamelCase());
complexBuilder.ComplexCollection(a => a.Rows, b =>
{
b.HasJsonPropertyName(nameof(DataTable.Rows).ToCamelCase());
b.Property(x => x.Name)
.HasJsonPropertyName(nameof(DataTable.DataTableRow.Name).ToCamelCase());
b.Property(x => x.Uuid)
.HasJsonPropertyName(nameof(DataTable.DataTableRow.Uuid).ToCamelCase());
b.PrimitiveCollection(x => x.Values)
.HasJsonPropertyName(nameof(DataTable.DataTableRow.Values).ToCamelCase());
});
return complexBuilder;
}
public record DataTable
{
public List<string> Headers { get; init; } = [];
public List<DataTableRow> Rows { get; init; } = [];
public record DataTableRow
{
public Guid Uuid { get; init; } = Guid.Empty;
public string Name { get; init; } = string.Empty;
public List<string> Values { get; init; } = [];
}
}Stack traces
No exception
Verbose output
EF Core version
10.0.0-rc.2.25502.107
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.NET 10 RC2
Operating system
Windows 11 localy, Azure Linux service plan
IDE
Visual Studio 2026