2

We manage the structure of our database using a SQL Server Data Tools project (.sqlproj), creating new objects in Visual Studio and publishing them to the SQL Server instances (directly or by generating a publish script).

SSDT automatically names FKs using the format

FK_ThisTable_ThatTable

We use SqlMetal to generate a Linq-to-SQL DBML.

<Table Name="dbo.Foo" Member="Foos">
  <Type Name="Foo">
    <Column Name="FooID" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
    <Column Name="Value" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
    <Column Name="BarID" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
    <Association Name="FK_Foo_Bar" Member="Bar" ThisKey="BarID" OtherKey="BarID" Type="Bar" IsForeignKey="true" DeleteOnNull="true" />
  </Type>
</Table>

If I open the DBML in VisualStudio's designer, modify the diagram layout and save, the DBML now contains

    <Association Name="Bar_Foo" Member="Bar" ThisKey="BarID" OtherKey="BarID" Type="Bar" IsForeignKey="true" DeleteOnNull="true" />

This means the history of our DBML file in TFS source control is a lot harder to read due to the unnecessary changes made by MSLinqToSQLGenerator and the restoration of the original names after running SqlMetal.

How do I stop Visual Studio's DBML Designer from modifying the FK names?

Emyr
  • 2,351
  • 18
  • 38

0 Answers0