Skip to content

Default PK Name for SQL SERVER #237

Closed
wants to merge 2 commits into from

2 participants

@adamlepkowski

First commit: I added following pattern PK_{TABLE_NAME}_{ColumnName} for the name of the primary key for SQL SERVER.

Second commit:
I added PrimaryKeyName attribute which allows user specify custom name of the primary key. That name may contains two format items: {0} - table name {1} - column name. This attribute is only supported in Sql Server.

Commits connected with Issue #229

adamlepkowski added some commits May 14, 2013
@adamlepkowski adamlepkowski Added creating primary key name with following pattern: [PK_{TABLE_NA…
…ME}_{ColumnName}] during CreateTable() process for MS SQL SERVER
721d60b
@adamlepkowski adamlepkowski Added new PrimaryKeyName attribute whereby user can specify name of t…
…he primary key. Attribute supported only in Sql Server
1150ff1
@mythz
ServiceStack member
mythz commented May 14, 2013

I'm not a fan of duplicating and repeating most of the entire logic since future features will not benefit the SqlServer provider. It's best instead to call an empty/no-op virtual method in the base class (that's overridden in the sub type) that abstracts the differences.

@adamlepkowski

Do you mean ToCreateTableStatement method in SqlServerOrmLiteDialectProvider class? If yes then I thought about it and finally I decided to copy entire logic from base method and then make a little change - I chose this solution because I found some similar solution in existing code.

@mythz
ServiceStack member
mythz commented May 14, 2013

Yep that's what I meant. Either way this isn't the way forward, the SqlServer provider is one of the most used providers, it should not be detached from the base code-base.

The differences should be extracted out, does this change make sense to be in other DB Providers? If so it should be kept in the common code, if not, only the differences should be extracted out.

@adamlepkowski

Ok, is this solution acceptable for you: I override ToCreateTableStatement method in sql provider but inside I invoke base method which return text(sql) and after that I make replace for primary key name?

What do you think about the new PrimaryKeyNameAttribute?

@mythz
ServiceStack member
mythz commented May 14, 2013

Not in love with either. It sounds like it's better off being a convention that's overridable in the config. I guess it's hard to explain what I was looking for. Better let me handle it when I have time.

@adamlepkowski

Yes it's a bit hard to understand what you want;) because I don't know your style. I'm waiting for your solution.

@mythz
ServiceStack member
mythz commented May 14, 2013

Yeah, don't wait for me for this as my todo list is infinitely long - work off your own fork builds till I find the time to get around to this.

@mythz mythz closed this Apr 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.