Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply column comments when creating tables #16750

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,28 @@ 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