src/EntityFramework/Migrations/Design/CSharpMigrationCodeGenerator.cs
/// <summary>
/// Generates code to perform an <see cref="AddForeignKeyOperation" />.
/// </summary>
/// <param name="addForeignKeyOperation"> The operation to generate code for. </param>
/// <param name="writer"> Text writer to add the generated code to. </param>
Generates code to perform an .
Generates code to perform an .
protected virtual void Generate(AddForeignKeyOperation addForeignKeyOperation, IndentedTextWriter writer)
        {
            Check.NotNull(addForeignKeyOperation, "addForeignKeyOperation");
            Check.NotNull(writer, "writer");
            writer.Write("AddForeignKey(");
            writer.Write(Quote(addForeignKeyOperation.DependentTable));
            writer.Write(", ");
            var compositeKey = addForeignKeyOperation.DependentColumns.Count() > 1;
            if (compositeKey)
            {
                writer.Write("new[] { ");
            }
            writer.Write(addForeignKeyOperation.DependentColumns.Join(Quote));
            if (compositeKey)
            {
                writer.Write(" }");
            }
            writer.Write(", ");
            writer.Write(Quote(addForeignKeyOperation.PrincipalTable));
            if (addForeignKeyOperation.PrincipalColumns.Any())
            {
                writer.Write(", ");
                if (compositeKey)
                {
                    writer.Write("new[] { ");
                }
                writer.Write(addForeignKeyOperation.PrincipalColumns.Join(Quote));
                if (compositeKey)
                {
                    writer.Write(" }");
                }
            }
            if (addForeignKeyOperation.CascadeDelete)
            {
                writer.Write(", cascadeDelete: true");
            }
            if (!addForeignKeyOperation.HasDefaultName)
            {
                writer.Write(", name: ");
                writer.Write(Quote(addForeignKeyOperation.Name));
            }
            writer.WriteLine(");");
        }
protected virtual void Generate ( AddForeignKeyOperation addForeignKeyOperation , IndentedTextWriter writer ) { Check . NotNull ( addForeignKeyOperation , " " ) ; Check . NotNull ( writer , " " ) ; writer . Write ( " " ) ; writer . Write ( Quote ( addForeignKeyOperation . DependentTable ) ) ; writer . Write ( " " ) ; var compositeKey = addForeignKeyOperation . DependentColumns . Count ( ) > 1 ; if ( compositeKey ) { writer . Write ( " " ) ; } writer . Write ( addForeignKeyOperation . DependentColumns . Join ( Quote ) ) ; if ( compositeKey ) { writer . Write ( " " ) ; } writer . Write ( " " ) ; writer . Write ( Quote ( addForeignKeyOperation . PrincipalTable ) ) ; if ( addForeignKeyOperation . PrincipalColumns . Any ( ) ) { writer . Write ( " " ) ; if ( compositeKey ) { writer . Write ( " " ) ; } writer . Write ( addForeignKeyOperation . PrincipalColumns . Join ( Quote ) ) ; if ( compositeKey ) { writer . Write ( " " ) ; } } if ( addForeignKeyOperation . CascadeDelete ) { writer . Write ( " " ) ; } if ( ! addForeignKeyOperation . HasDefaultName ) { writer . Write ( " " ) ; writer . Write ( Quote ( addForeignKeyOperation . Name ) ) ; } writer . WriteLine ( " " ) ; }
Generates code to perform an .
Generates code to perform an .
addForeignKeyOperation
AddForeignKeyOperation
The operation to generate code for.
The operation to generate code for .
writer
IndentedTextWriter
Text writer to add the generated code to.
Text writer to add the generated code to .