Names and default names for keys, constraints and indices
Nobody has claimed this yet.
Assessment
This issue has not been assessed yet.
Description
While working on #12821, I noticed some that may merit some discussion.
When scaffolding, RelationalScaffoldingModelFactory checks the database name for keys, constraints and indices, comparing them against the default name EF Core would assign to this index. The idea is presumably to avoid useless scaffolding HasName() calls which would bloat OnModelCreating().
Now, at least in the PostgreSQL case (but I think also the others), a name is always returned for keys/constraints/indices. PostgreSQL has its own defaults: primary keys that haven't been explicitly named are called {table}_pkey, etc. This means that for a typical database that has been created without specifying names, HasName() will be scaffolded everywhere because the PostgreSQL defaults aren't the same as the EF Core defaults (PK_{table}).
There seem to be two options:
- Current behavior: always take the name reported by the database. This bloats
OnModelCreating()withHasName()calls on every single key, constraint and index. But it does have the advantage of round-trippability (exact names are preserved from the scaffolded database). - Alternative behavior: have the database model factories omit names when those names are the database defaults, leading to null names and less
HasName()everywhere. Since EF Core must specify names when creating keys/indices, it would see nullls and default create indexes and keys with its own defaults.
Basically it's a choice between round-trippability (current behavior) and a leaner OnModelCreating(). I'm not sure to what extent the former is an actual goal.
What do you guys think?
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100