locked
Changing the prefix for foreign keys in SSDLToSQL20.tt RRS feed

  • Question

  • I'm attempting to modify the prefixes generated by SSDLToSQL10.tt.  I'd like to have my indexes begin with "nci" and my foreign keys begin with "fk".  I'm looking at SSDLToSQL10.tt, and I see a variable or function called "WriteFKConstraintName".  I can't figure out how to change the value of "WriteFKConstraintName".

    Does anyone know if it's possible to change the value of "WriteFKConstraintName" so it doesn't add "FK_" to the foreign key names it generates?

    Friday, September 23, 2011 8:27 PM

Answers

  • Hi Ken,

    Welcome!

    You just need to remove "WriteFKConstraintName", you will find "FK_" remove from your DDL too.

    ALTER TABLE <#if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>]
    ADD CONSTRAINT [<#=constraint#>]
        FOREIGN KEY (<#=WriteColumns(constraint.ToProperties, ',')#>)
    

    1. Edit it and save it on other folder and rename it then copy it to : C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen
    2. Choose the template in Edmx.

    3. Generate the DDL.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Monday, October 3, 2011 7:33 AM
    Monday, September 26, 2011 9:20 AM

All replies

  • Hi Ken,

    Welcome!

    You just need to remove "WriteFKConstraintName", you will find "FK_" remove from your DDL too.

    ALTER TABLE <#if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>]
    ADD CONSTRAINT [<#=constraint#>]
        FOREIGN KEY (<#=WriteColumns(constraint.ToProperties, ',')#>)
    

    1. Edit it and save it on other folder and rename it then copy it to : C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen
    2. Choose the template in Edmx.

    3. Generate the DDL.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Monday, October 3, 2011 7:33 AM
    Monday, September 26, 2011 9:20 AM
  • Hi,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 28, 2011 3:30 AM