2

Closed

Designer: DDL Generation Template for SQL CE should seperate each statemenet with GO

description

Currently this is not the case for all statements, and it would be consistent and convenient if this was the case.
Closed Jan 16 at 12:59 AM by jemartti
Great fix, thanks Erik.

comments

moozzyk wrote Jan 28, 2013 at 2:32 AM

Please provide more details on benefits of having this?
DDL is created by a T4 template that can be modified or you can provide your own T4 template (can be created based on the one that is shipped with VS) to generate DDL the way you want it.
The template I am talking about is located here:
c:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToSQL10.tt

ErikEJ wrote Jan 28, 2013 at 7:04 AM

The benefit would be that the script is consistent and reliable. It is only foreign key constraints that lack the GO, all other statements have it. I will blog about the required change.
<#
    foreach (AssociationSet associationSet in Store.GetAllAssociationSets())
    {
        ReferentialConstraint constraint = associationSet.ElementType.ReferentialConstraints.Single();
        AssociationSetEnd dependentSetEnd = associationSet.AssociationSetEnds.Where(ase => ase.CorrespondingAssociationEndMember == constraint.ToRole).Single();
        AssociationSetEnd principalSetEnd = associationSet.AssociationSetEnds.Where(ase => ase.CorrespondingAssociationEndMember == constraint.FromRole).Single();
        string schemaName = Id(dependentSetEnd.EntitySet.GetSchemaName());
        string dependentTableName = Id(dependentSetEnd.EntitySet.GetTableName());
        string principalTableName = Id(principalSetEnd.EntitySet.GetTableName());
#>
-- Creating foreign key on <#=WriteColumns(constraint.ToProperties, ',')#> in table '<#=dependentTableName#>'
ALTER TABLE <#if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>]
ADD CONSTRAINT [<#=WriteFKConstraintName(constraint)#>]
    FOREIGN KEY (<#=WriteColumns(constraint.ToProperties, ',')#>)
    REFERENCES <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=principalTableName#>]
        (<#=WriteColumns(constraint.FromProperties, ',')#>)
    ON DELETE <#=GetDeleteAction(constraint)#> ON UPDATE NO ACTION;
GO
<#      
        // if the foreign keys are part of the primary key on the dependent end, then we should not add a constraint.
        if (!dependentSetEnd.EntitySet.ElementType.GetKeyProperties().Take(constraint.ToProperties.Count()).OrderBy(r => r.Name).SequenceEqual(constraint.ToProperties.OrderBy(r => r.Name)))
        {
#>

-- Creating non-clustered index for FOREIGN KEY '<#=WriteFKConstraintName(constraint)#>'
CREATE INDEX [IX_<#=WriteFKConstraintName(constraint)#>]
ON <#if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>]
    (<#=WriteColumns(constraint.ToProperties, ',')#>);
GO
<#      
        }
#>

<#
    }
#>
-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------

RoMiller wrote Jan 31, 2013 at 10:30 PM

EF Team Triage: We are only taking minimal changes to the designer in EF6 because we are still converting the code base to open source. We'll consider this issue for the next release.

ErikEJ wrote Feb 1, 2013 at 8:02 AM

Thanks for the update, I will just blog about my proposed update and make it available for download

moozzyk wrote Feb 1, 2013 at 4:18 PM

@Erikj: Reply we are working on making the designer open source. Once it is published you will be welcome to contribute your change back to the product.

ErikEJ wrote Feb 1, 2013 at 4:55 PM

Thanks, I will look forward to that, in the meantime I blogged about my fix here: http://erikej.blogspot.dk/2013/02/fixing-entity-framework-designer.html

ErikEJ wrote Nov 11, 2013 at 5:29 PM

@Moozyk - Sorry I missed the tests, how does one run the Inproc tests?

moozzyk wrote Nov 11, 2013 at 6:29 PM

@ErikEJ - When processing your pull request I realized that the steps for contributing code were not updated for tooling (I did update them a couple hours ago). The easiest way to setup everything (and to test the change before checking in) is to run BuildEFTools.cmd which is a counterpart of build.cmd for runtime. It will install the VsIdeHostAdapter (if needed) which will enable running the InProcTests. Once the VsIdeHostAdapter is installed you should be able to run and debug the InProc tests from VS - they are MSTests (because they need the custom test host we did not port them to xUnit) and you use the built-in test explorer to run them. Note, the test runner from Re# does not handle these tests correctly - I believe that this is because of the custom test host. I don't typically run the InProcTests when working on the code since we lean more towards unit tests which are faster and allow for more targeted coverage but I always run BuildEFTools.cmd before checking in to make sure I did not break anything.

ErikEJ wrote Nov 11, 2013 at 7:42 PM

I did Refer to the guide, but i ran buildeftools t:/Install.

Should I simply run buildeftools with no /t option instead?

moozzyk wrote Nov 11, 2013 at 8:25 PM

Yes. /t:Installs only builds and install the designer but does not run tests.

moozzyk wrote Jan 3 at 4:49 PM

Fixed by ErikEJ in changeset #59e224d

NoGONOMore

Fix for issue https://entityframework.codeplex.com/workitem/824 (DDL Generation Template for SQL CE should seperate each statemenet with GO)