Skip to content

Entity splitting not working correctly due to PK constraint naming conflict #3639

@erick-thompson

Description

@erick-thompson

This is using the feature where some properties of an entity are mapped to a different table.

The core of the problem is that PK constraint names need to be unique in Postgres. The way that EF generates the PK constraint names results in conflicts when creating the database using EnsureCreated. There appears to be no way to mitigate this due to the way that names are generated.

The EnsureCreated path ends up calling RelationalKeyExtensions.GetName to get the name of the PK constraint. Because both the primary and split mapping have the same entity, and thus the same PrimaryKey, the name of the PK ends up identical on both tables, and the available override via annotation applies to the key, not the StoredObject. The net effect is that EF always creates the same name for both PK constraints, which fails as it's not unique.

The pgcontext.Database.Migrate path does not have the same issue, and there are multiple ways to customize the names.

The lack of a workaround is that there are no injection points to modify the name of the constraint at creation time, and the code doesn't allow for a table/StoredObject scoped constraint name.

I can provide sample code if that would help.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions