Repository navigation
Description
Found in the 5.5.0 pre-tag review (#36).
#92 made the core differ refuse a model whose complex indexes carry a satellite's index options, because UseComplexIndexes() in place of the satellite's registration (or a missing satellite .targets at design time) applied the rest cleanly without them. The refusal stops at index options. Everything else only a satellite differ does is still dropped without a word, so the shape #92 was a Changed answer for is still open.
Reproduction (934ec55)
PostgreSQL, a context registered with the core method:
public class Grant { public int Id { get; set; } public int GranteeId { get; set; } public NpgsqlRange<DateOnly> Period { get; set; } public string Code { get; set; } = ""; }
protected override void OnModelCreating(ModelBuilder m) => m.Entity<Grant>(b =>
{
b.ToTable("grants");
b.HasExclusionConstraint(x => x.GranteeId, x => x.Period, name: "ex_grant_no_overlap");
b.HasTemporalConstraint(x => x.Code, x => x.Period);
b.HasComplexIndex(x => x.Code, isUnique: true, indexName: "ux_code");
});
new DbContextOptionsBuilder<Ctx>().UseNpgsql(cs).UseComplexIndexes(); // instead of UseNpgsqlComplexIndexes()
ctx.Database.GenerateCreateScript();UseComplexIndexes(): EXCLUDE present: False, WITHOUT OVERLAPS present: False, ux_code present: True
UseNpgsqlComplexIndexes(): EXCLUDE present: True, WITHOUT OVERLAPS present: True, ux_code present: True
EnsureCreated() applies that script cleanly, and Migrate()'s pending-model-changes check never sees a constraint change.
SQL Server, a unique complex index on an optional complex property (#88's case):
UseComplexIndexes(): CREATE UNIQUE INDEX [ux_vin] ON [cars] ([Registration_Vin]);
UseSqlServerComplexIndexes(): CREATE UNIQUE INDEX [ux_vin] ON [cars] ([Registration_Vin]) WHERE [Registration_Vin] IS NOT NULL;
The core leaves out #88's implicit filter (ImplicitFilter returns null there), so the second row without a registration is refused as a duplicate: #88's bug, back under the core registration.
What it does / what it should do
- Does: the table is created without the exclusion constraint, the temporal constraint or the temporal FK, and the SQL Server unique index has no
IS NOT NULLfilter. No error, and the apply is clean. - Should: fail as The core differ silently drops SQL Server and Npgsql index options when it diffs a model a satellite should #92 does and name the satellite's registration. The XML remarks on
UseComplexIndexes()say this gives "a schema without the satellite's features, such as exclusion constraints". The upgrade guide justifies The core differ silently drops SQL Server and Npgsql index options when it diffs a model a satellite should #92 with "The core differ runs where the satellite's should when an application callsUseComplexIndexes()". Both describe the defect; neither prevents it.
Proposed fix
In CustomMigrationsModelDiffer.ValidateNoSatelliteOptions (src/EFCore.ComplexIndexes/CustomMigrationsModelDiffer.cs:986), when _satellite is set and the core differ is running, do one of these:
- Narrow: also refuse any
CustomExclusion:/CustomTemporal:declaration on the target model, and on SQL Server any unique complex index thatImplicitFilterwould filter. - Simpler: refuse every complex-index or constraint declaration, since the satellite's differ is the one that should run.
Keep it target-only, as every check is.
Tests:
- Npgsql +
UseComplexIndexes()+HasExclusionConstraint→GenerateCreateScript()throws, namingUseNpgsqlComplexIndexes(). - The same for
HasTemporalConstraint. - SQL Server +
UseComplexIndexes()+ a nullable unique complex index → throws, namingUseSqlServerComplexIndexes(). - SQLite with the same declarations → unaffected.
A fix turns a clean EnsureCreated() into a refusal, which is a changed answer. release/5.x cannot ship that after the tag, so it goes in 5.5.0 under ### Changed answers, with its docs/upgrading.md entry beside #92's.
Activity
CaffeinatedCoder commentedon Oct 20, 2026
Fixed in #162 with the narrow variant: the core differ refuses the PostgreSQL satellite's exclusion constraints, temporal constraints and temporal foreign keys, and on SQL Server a unique complex index over nullable columns with no filter. It refuses them only when a satellite serves the provider and the running differ is not the satellite's. That check is merged into #92's, so there is one validation, and it reads the target model only. Each part of the fix was reverted to prove its tests: unit tests, PostgreSQL 18 integration, and the SQL Server 2022 CI lane.
Merge pull request #162 from CaffeinatedCoder/claude/150-core-refuses…
docs: say the core registration fails on a provider package's features (