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
We are using EF with NamingConventions and Npgsql, all in their latest versions.
PostgreSQL has a 63-character limit for column names that Npgsql announces as a RelationalMaxIdentifierLengthConvention.
Without NamingConventions, column names are abbreviated using a ~, ~1, ~2, ... style.
Issue
When using the Snake Case naming convention, this abbreviation does not work as expected if the original C# property name fits within the limit, but the Snake Case version is longer than 63 characters.
To reproduce
Enable the Snake Case naming convention via optionsBuilder.UseSnakeCaseNamingConvention();
Create an Entity with a property named ProviderCreditorUpdateNotificationsLastSendingByEmailsFailedAt (62 characters long)
Create a migration
Expected result
The respective table column is called provider_creditor_update_notifications_last_sending_by_emails_~ (63 characters, fully supported).
Actual result
The respective table column in the migration is called provider_creditor_update_notifications_last_sending_by_emails_failed_at (71 characters), which Postgres then silently truncates to provider_creditor_update_notifications_last_sending_by_emails_f, resulting in all kinds of issues.
Further thoughts
If the C# property name is already longer than 63 characters, the abbreviation in ~ style works as expected. The issue only occurs if the property name is shorter than 63 or exactly 63 characters long, but the Snake Case version is longer than the limit.
What seems to happen here is that when deciding if the column name fits into the 63 characters limit, the C# property name (without underscores) is used. However, the Snake Case underscores push the column name over the limit.
I'm not totally sure if this is an issue for this repository? Apologies if it isn't!
The text was updated successfully, but these errors were encountered:
Sorry it took so long to respond, and yes, I can indeed see the bug.
@AndriySvyryd, when you have a spare moment... The naming convention sets e.g. column names, and it seems that the MaxIdentifierLength gets ignored; I'm not sure, but in the EF source code it seems that MaxIdentifierLength only gets consulted when returning default names, and not for by-convention/explicitly set ones. I'd expect there to be a convention which truncates/uniquifies names as they get set, but that doesn't seem to be the case right now.
I tried to add an explicit Uniquifier.Truncate() in the convention before calling SetColumnName(); that of course works, but no uniquification is performed (so that two very long properties get the same truncated column name). Here even more than the above, I'd expect uniquification to be done in EF rather than in this convention.
Let me know what you think, I can open issues in the EF repo.
roji
added a commit
to roji/EFCore.NamingConventions
that referenced
this issue
Nov 27, 2024
Environment
We are using EF with NamingConventions and Npgsql, all in their latest versions.
PostgreSQL has a 63-character limit for column names that Npgsql announces as a RelationalMaxIdentifierLengthConvention.
Without NamingConventions, column names are abbreviated using a
~
,~1
,~2
, ... style.Issue
When using the Snake Case naming convention, this abbreviation does not work as expected if the original C# property name fits within the limit, but the Snake Case version is longer than 63 characters.
To reproduce
optionsBuilder.UseSnakeCaseNamingConvention();
ProviderCreditorUpdateNotificationsLastSendingByEmailsFailedAt
(62 characters long)Expected result
The respective table column is called
provider_creditor_update_notifications_last_sending_by_emails_~
(63 characters, fully supported).Actual result
The respective table column in the migration is called
provider_creditor_update_notifications_last_sending_by_emails_failed_at
(71 characters), which Postgres then silently truncates toprovider_creditor_update_notifications_last_sending_by_emails_f
, resulting in all kinds of issues.Further thoughts
~
style works as expected. The issue only occurs if the property name is shorter than 63 or exactly 63 characters long, but the Snake Case version is longer than the limit.The text was updated successfully, but these errors were encountered: