When creating a foreign key that references multiple nullable columns in Postgresql it’s possible to add a match type of “MATCH FULL” on the foreign key to ensure that all values are either null, or are all required.
Is it possible to do this when creating the foreign key using Entity Framework Core?
For example given the relationship:
entity.HasOne(static e => e.Unit)
.WithMany(static e => e.Rules)
.HasForeignKey(static e => new
{
e.OwnerId,
e.UnitId,
})
.HasPrincipalKey(static e => new
{
e.OwnerId,
e.Id,
});
this would generate the DDL:
CONSTRAINT "FK_Rules_Units_OwnerId_UnitId"
FOREIGN KEY ("OwnerId","UnitId")
REFERENCES public."Units"("OwnerId","Id"),
but the desired output for this would be
CONSTRAINT "FK_Rules_Units_OwnerId_UnitId"
FOREIGN KEY ("OwnerId","UnitId")
REFERENCES public."Units"("OwnerId","Id")
MATCH FULL,
Is it possible to do this using the EntityTypeBuilder and related extension methods, or is the only way to do this to make a custom migration which re-creates that foreign key using raw SQL? It would be preferable to avoid raw SQL as this won’t be taken into account by Entity Framework when it creates future migrations.