-
-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: override PK property name to be always be Id #1222
Comments
You should be able to use the regex based renaming with individual override where needed. |
Sorry, not really sure what you mean by this. |
I mean this |
Thanks for this. I'm unable to make use of regex since I have no clue what the table/entity name is to match it on the column name when wanting this done for all tables/entities. Since I only have a few tables to deal with, I manually listed all out with the PK rename. Still, it will be nice to have this done across all tables somehow. Unless you have some tricks up your sleeves. |
You said they started with some letters and ended with Id... |
Yes but only for the PK column. To avoid hand jamming everything, I wrote the below query (on Sql Server 2016 or later) to generate the SELECT
schemas.name AS SchemaName,
Tables.Name,
Columns.Name,
'Id' AS NewName
FROM
sys.tables AS Tables
JOIN sys.schemas
ON schemas.schema_id = tables.schema_id
JOIN sys.indexes
ON indexes.object_id = tables.object_id
AND indexes.is_primary_key = 1
JOIN sys.index_columns
ON index_columns.object_id = indexes.object_id
AND index_columns.index_id = indexes.index_id
JOIN sys.columns AS Columns
ON columns.object_id = tables.object_id
AND columns.column_id = index_columns.column_id
FOR JSON AUTO |
Excellent, I will add that to the docs! |
I have an established (old) DB where the PK of each table is named: {TableName}Id
It would be nice to have a feature to reverse engineer to entities with the property named
Id
which maps to the table's PK. This helps keep things a bit consistent for us.Of course, if the table PK is already named
Id
, there is nothing to do. Same when encountering a table with composite PKs.The text was updated successfully, but these errors were encountered: