views:

72

answers:

1

I have created a very simple Entity Framework 4.0 model using VS2010 Professional. Ignore the Nationality entity which is a simple one-to-many relationship.

I have an Entry entity which has a many-to-many relationship with the Team entity because an Entry can have more than one team. This is represented below:

Entity model example

This then generates the following DDL:

...Some DDL...

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Nationalities'
CREATE TABLE [dbo].[Nationalities] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'Entries'
CREATE TABLE [dbo].[Entries] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [NationalityId] int  NOT NULL
);
GO

-- Creating table 'Teams'
CREATE TABLE [dbo].[Teams] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'EntryTeam'
CREATE TABLE [dbo].[EntryTeam] (
    [Entries_Id] int  NOT NULL,
    [Teams_Id] int  NOT NULL
);
GO

...More DDL...

As you can see I use TitleCaseId for my entity properties but the auto-generated entity which acts as a join table uses TitleCase_Id.

Rather than cause problems when others come to view the code is there an easy way of changing this somehow so that when the code is generated it can like my other entities both in the EDM and the DDL?

+1  A: 

You will notice on the properties Window when on the Entity Framework Model that there is a group of properties called "Database Script Generation".

What happens is that when you generate the scripts the Workflow "TablePerTypeStrategy.xaml" is run and uses a T4 template "SSDLToSQL10.tt" to transform your Entity Model into DDL scripts using the MS pre-defined conventions.

The T4 template is located in C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\

You can edit the SSDLToSQL10.tt file using your preferred convention, I would back it up first or alternatively create a copy and edit the copy, the new file will show up in the "DDL Generation Template" drop down in Visual Studio.

willbt