diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs index d0419e3ad2f..aefe3b6ca3d 100644 --- a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs +++ b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs @@ -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); diff --git a/test/EFCore.Relational.Specification.Tests/MigrationSqlGeneratorTestBase.cs b/test/EFCore.Relational.Specification.Tests/MigrationSqlGeneratorTestBase.cs index 23fb2c284ca..2dc8158bf13 100644 --- a/test/EFCore.Relational.Specification.Tests/MigrationSqlGeneratorTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/MigrationSqlGeneratorTestBase.cs @@ -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 { @@ -534,7 +535,8 @@ public virtual void CreateTableOperation() PrincipalTable = "Companies", PrincipalColumns = new[] { "Id" } } - } + }, + Comment = "Table comment" }); [ConditionalFact] diff --git a/test/EFCore.SqlServer.FunctionalTests/SqlServerMigrationSqlGeneratorTest.cs b/test/EFCore.SqlServer.FunctionalTests/SqlServerMigrationSqlGeneratorTest.cs index 070f83269d5..c52074c7feb 100644 --- a/test/EFCore.SqlServer.FunctionalTests/SqlServerMigrationSqlGeneratorTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/SqlServerMigrationSqlGeneratorTest.cs @@ -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();