You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Repeated UpdateData for List<string> property with HasData and migrations #3635
When using EF Core's HasData to seed data for an entity that contains a List property, every time I run Add-Migration, even if nothing has changed in the entity or the seed data, EF Core generates UpdateData statements for the List field.
The below is an AI-generated analysis and may contain inaccuracies.
Confirmed as an Npgsql-specific bug, with a regression boundary between 6.x and 7.0.0, rather than a new regression in 9.0.4. The issue remains classified as Bug.
With Npgsql/EF 9.0.4, scaffolding an initial migration and then two more migrations without changing the model or seed data produces the same UpdateData in both subsequent migrations, in both Up and Down. Comparing two independently built, identical models also reproduces this directly through IMigrationsModelDiffer; no database connection, database creation, or data insertion is required.
Version and provider comparison
Representative results from the standalone model-differ repro:
Provider
Provider package version
EF Core version
Differences for identical seed data
Npgsql
6.0.7
6.0.7
None
Npgsql
6.0.29
6.0.36
None
Npgsql
7.0.0
7.0.0
One redundant update
Npgsql
8.0.11
8.0.31
One redundant update
Npgsql
9.0.4
9.0.4
One redundant update
Npgsql
9.0.4
9.0.21
One redundant update
Npgsql
10.0.3
10.0.13
One redundant update
Npgsql
11.0.0-rc.1.1
11.0.0-rc.1.26425.128
One redundant update
SQL Server
9.0.4
9.0.4
None
The stable-package comparisons were run on .NET 10; the 11 prerelease comparison was run on .NET 11 RC2. The original .NET 9 runtime was not used.
Comparer mismatch
For two distinct List<string> instances containing "A", "B", "C", the Npgsql 9.0.4 property comparers give:
Explicitly setting a sequence-based ValueComparer<List<string>>, as in the workaround above, removed the difference. Scaffolding another migration against the existing snapshot with that comparer configured also produced an empty migration.
Related issues
dotnet/efcore#36942 is the same report, already closed after it did not reproduce on SQL Server and was redirected here. The independent SQL Server comparison above agrees with that result; this issue should remain in the Npgsql repository.
dotnet/efcore#27374 has a similar repeated-seed-update symptom for spatial values, but is not an established duplicate of this primitive-list mapping bug.
EnableServiceProviderCaching(false) ensures that the two contexts build independent models, rather than comparing the same cached model and seed objects.
Run dotnet run. Expected: no migration SQL. Actual:
Activity
roji commentedon Oct 11, 2025
Thanks @Varorbc, I can see this happening now - will investigate.
zlepper commentedon Dec 1, 2025
As a workaround, i have done this in
OnModelCreating:It's a bit of a brute-force solution, but it at least prevents the extra migration changes :)
roji commentedon Oct 18, 2026
AI Triage
The below is an AI-generated analysis and may contain inaccuracies.
Confirmed as an Npgsql-specific bug, with a regression boundary between 6.x and 7.0.0, rather than a new regression in 9.0.4. The issue remains classified as Bug.
With Npgsql/EF 9.0.4, scaffolding an initial migration and then two more migrations without changing the model or seed data produces the same
UpdateDatain both subsequent migrations, in bothUpandDown. Comparing two independently built, identical models also reproduces this directly throughIMigrationsModelDiffer; no database connection, database creation, or data insertion is required.Version and provider comparison
Representative results from the standalone model-differ repro:
The stable-package comparisons were run on .NET 10; the 11 prerelease comparison was run on .NET 11 RC2. The original .NET 9 runtime was not used.
Comparer mismatch
For two distinct
List<string>instances containing"A", "B", "C", the Npgsql 9.0.4 property comparers give:GetValueComparer()trueGetKeyValueComparer()falseGetProviderValueComparer()falseEF 6 compares model seed values using the value comparer, whereas EF 7's seed-data differ uses the column's provider value comparer. The Npgsql array mapping supplies an element-wise value comparer but does not explicitly supply a key/provider comparer. This explains why equal list contents can nevertheless be treated as changed by migrations.
Explicitly setting a sequence-based
ValueComparer<List<string>>, as in the workaround above, removed the difference. Scaffolding another migration against the existing snapshot with that comparer configured also produced an empty migration.Related issues
minimal repro
Repro.csproj:Program.cs:EnableServiceProviderCaching(false)ensures that the two contexts build independent models, rather than comparing the same cached model and seed objects.Run
dotnet run. Expected: no migration SQL. Actual:For the original scaffolding scenario, using
dotnet-ef9.0.4 in a fresh copy of the project:Both
UnchangedandStillUnchangedcontain:[8.0] Fix repeated seed-data updates for list properties (#4028)