-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Bug description
@roji I don't know how to be able to repro this without spending hours trying to tear down my existing project. So I'll try to provide as much context as possible, but essentially I have an .NET 10 minimal API based project that uses EntityFrameworkCore 9.0.7. If I upgrade to version 10.0.0-preview.6.25358.103 and create a new migration with absolutely no code changes, it create a migration for all of the columns where a ComplexProperty is configured. Even if I create the migration, it will throw PendingModelChangesWarning on startup. I can create as many migrations as I'd like, they're always identical.
My best guess is that it seems to be related to detecting nullability around structs.
Your code
Relevants bits of code:
public sealed class City
{
public int CityId { get; init; }
public required Coordinates Location { get; init; }
}
internal sealed class CityConfiguration : IEntityTypeConfiguration<City>
{
public void Configure(EntityTypeBuilder<City> entity)
{
entity.HasKey(e => e.CityId);
entity.Property(e => e.CityId)
.ValueGeneratedOnAdd();
entity.ComplexProperty(e => e.Location, builder =>
{
builder.Property(e => e.Latitude)
.HasColumnType("decimal(9, 6)");
builder.Property(e => e.Longitude)
.HasColumnType("decimal(9, 6)");
}
);
}
}
// Value objects have been simplified
public readonly struct Coordinates
{
public Latitude Latitude { get; init; }
public Longitude Longitude { get; init; }
}
public readonly struct Coordinates
{
public Latitude Latitude { get; private init; }
public Longitude Longitude { get; private init; }
private Coordinates()
{
}
public static Coordinates Create(Latitude latitude, Longitude longitude)
{
return new Coordinates { Latitude = latitude, Longitude = longitude };
}
}
public readonly struct Latitude
{
private decimal _value;
private Latitude(decimal value)
{
_value = value;
}
public static Latitude Create(decimal value)
{
return new Latitude(value);
}
public decimal ToDecimal()
{
return _value;
}
}
public readonly struct Longitude
{
private decimal _value;
private Longitude(decimal value)
{
_value = value;
}
public static Longitude Create(decimal value)
{
return new Longitude(value);
}
public decimal ToDecimal()
{
return _value;
}
}I wire up value converters around Latitude and Longitude.
The migrations it will create will look like this:
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Database.Migrations
{
/// <inheritdoc />
public partial class PendingModelChanges : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<decimal>(
name: "Longitude",
table: "City",
type: "decimal(9,6)",
nullable: false,
defaultValue: 0m,
oldClrType: typeof(decimal),
oldType: "decimal(9,6)",
oldNullable: true);
migrationBuilder.AlterColumn<decimal>(
name: "Latitude",
table: "City",
type: "decimal(9,6)",
nullable: false,
defaultValue: 0m,
oldClrType: typeof(decimal),
oldType: "decimal(9,6)",
oldNullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<decimal>(
name: "Longitude",
table: "City",
type: "decimal(9,6)",
nullable: true,
oldClrType: typeof(decimal),
oldType: "decimal(9,6)");
migrationBuilder.AlterColumn<decimal>(
name: "Latitude",
table: "City",
type: "decimal(9,6)",
nullable: true,
oldClrType: typeof(decimal),
oldType: "decimal(9,6)");
}
}
}I wish I could provide better code examples, but there's a lot of code dependencies that make it complex for me to water down my project into a focused repro.
EF Core version
10.0.0-preview.6.25358.103
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.NET 10.0.0-preview.6.25358.103
Operating system
Windows 11
IDE
JetBrains Rider 2025.2 RC 1