Skip to content

Commit

Permalink
Apply column comments when creating tables
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Jul 25, 2019
1 parent c39853f commit c31ec2a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ protected virtual void Generate(
GenerateComment(operation, model, builder, operation.Comment, operation.Schema, operation.Name);
}

foreach (var column in operation.Columns.Where(c => c.Comment != null))
{
GenerateComment(operation, model, builder, column.Comment, operation.Schema, operation.Name, column.Name);
}

if (terminate)
{
builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ public virtual void CreateTableOperation()
Name = "EmployerId",
Table = "People",
ClrType = typeof(int),
IsNullable = true
IsNullable = true,
Comment = "Employer ID comment"
},
new AddColumnOperation
{
Expand Down Expand Up @@ -534,7 +535,8 @@ public virtual void CreateTableOperation()
PrincipalTable = "Companies",
PrincipalColumns = new[] { "Id" }
}
}
},
Comment = "Table comment"
});

[ConditionalFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ namespace Microsoft.EntityFrameworkCore
{
public class SqlServerMigrationSqlGeneratorTest : MigrationSqlGeneratorTestBase
{
public override void CreateTableOperation()
{
base.CreateTableOperation();

Assert.Equal(
@"CREATE TABLE [dbo].[People] (
[Id] int NOT NULL,
[EmployerId] int NULL,
[SSN] char(11) NULL,
PRIMARY KEY ([Id]),
UNIQUE ([SSN]),
CHECK (SSN > 0),
FOREIGN KEY ([EmployerId]) REFERENCES [Companies] ([Id])
)GO
EXEC sp_addextendedproperty @name = N'Comment', @value = N'Table comment', @level0type = N'Schema', @level0name = N'dbo', @level1type = N'Table', @level1name = N'People'GO
EXEC sp_addextendedproperty @name = N'Comment', @value = N'Employer ID comment', @level0type = N'Schema', @level0name = N'dbo', @level1type = N'Table', @level1name = N'People', @level2type = N'Column', @level2name = N'EmployerId';
", Sql, ignoreLineEndingDifferences: true);
}

public override void CreateIndexOperation_with_filter_where_clause()
{
base.CreateIndexOperation_with_filter_where_clause();
Expand Down

0 comments on commit c31ec2a

Please sign in to comment.