CodePlexProject Hosting for Open Source Software
An unexpected error has occured.
There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Voted
No files are attached
moozzyk wrote Jan 28 at 2:32 AM
ErikEJ wrote Jan 28 at 7:04 AM
<# 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 at 10:30 PM
ErikEJ wrote Feb 1 at 8:02 AM
moozzyk wrote Feb 1 at 4:18 PM
ErikEJ wrote Feb 1 at 4:55 PM
Sign in to add a comment or to set email notifications
Keyboard shortcuts are available for this page.