src/Shared/EntityFramework/Migrations/Design/CSharpMigrationCodeGenerator.cs
/// <summary>
/// Generates code to perform a <see cref="CreateTableOperation" />.
/// </summary>
/// <param name="createTableOperation"> The operation to generate code for. </param>
/// <param name="writer"> Text writer to add the generated code to. </param>
Generates code to perform a .
Generates code to perform a .
protected virtual void Generate(CreateTableOperation createTableOperation, IndentedTextWriter writer)
        {
            Check.NotNull(createTableOperation, "createTableOperation");
            Check.NotNull(writer, "writer");
            writer.WriteLine("CreateTable(");
            writer.Indent++;
            writer.Write(Quote(createTableOperation.Name));
            writer.WriteLine(",");
            writer.WriteLine("c => new");
            writer.Indent++;
            writer.WriteLine("{");
            writer.Indent++;
            createTableOperation.Columns.Each(
                c =>
                {
                    var scrubbedName = ScrubName(c.Name);
                    writer.Write(scrubbedName);
                    writer.Write(" =");
                    Generate(c, writer, !string.Equals(c.Name, scrubbedName, StringComparison.Ordinal));
                    writer.WriteLine(",");
                });
            writer.Indent--;
            writer.Write("}");
            writer.Indent--;
            if (createTableOperation.Annotations.Any())
            {
                writer.WriteLine(",");
                writer.Write("annotations: ");
                GenerateAnnotations(createTableOperation.Annotations, writer);
            }
            writer.Write(")");
            GenerateInline(createTableOperation.PrimaryKey, writer);
            _newTableForeignKeys
                .Where(t => t.Item1 == createTableOperation)
                .Each(t => GenerateInline(t.Item2, writer));
            _newTableIndexes
                .Where(t => t.Item1 == createTableOperation)
                .Each(t => GenerateInline(t.Item2, writer));
            writer.WriteLine(";");
            writer.Indent--;
            writer.WriteLine();
        }
protected virtual void Generate ( CreateTableOperation createTableOperation , IndentedTextWriter writer ) { Check . NotNull ( createTableOperation , " " ) ; Check . NotNull ( writer , " " ) ; writer . WriteLine ( " " ) ; writer . Indent ++ ; writer . Write ( Quote ( createTableOperation . Name ) ) ; writer . WriteLine ( " " ) ; writer . WriteLine ( " " ) ; writer . Indent ++ ; writer . WriteLine ( " " ) ; writer . Indent ++ ; createTableOperation . Columns . Each ( c => { var scrubbedName = ScrubName ( c . Name ) ; writer . Write ( scrubbedName ) ; writer . Write ( " " ) ; Generate ( c , writer , ! string . Equals ( c . Name , scrubbedName , StringComparison . Ordinal ) ) ; writer . WriteLine ( " " ) ; } ) ; writer . Indent -- ; writer . Write ( " " ) ; writer . Indent -- ; if ( createTableOperation . Annotations . Any ( ) ) { writer . WriteLine ( " " ) ; writer . Write ( " " ) ; GenerateAnnotations ( createTableOperation . Annotations , writer ) ; } writer . Write ( " " ) ; GenerateInline ( createTableOperation . PrimaryKey , writer ) ; _newTableForeignKeys . Where ( t => t . Item1 == createTableOperation ) . Each ( t => GenerateInline ( t . Item2 , writer ) ) ; _newTableIndexes . Where ( t => t . Item1 == createTableOperation ) . Each ( t => GenerateInline ( t . Item2 , writer ) ) ; writer . WriteLine ( " " ) ; writer . Indent -- ; writer . WriteLine ( ) ; }
Generates code to perform a .
Generates code to perform a .
createTableOperation
CreateTableOperation
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 .