diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs index a219bb011b0..56a0bd8bd8a 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs @@ -606,6 +606,7 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations) RemoveAnnotation(ref annotations, CoreAnnotationNames.Unicode); RemoveAnnotation(ref annotations, RelationalAnnotationNames.DefaultValue); RemoveAnnotation(ref annotations, RelationalAnnotationNames.DefaultValueSql); + RemoveAnnotation(ref annotations, RelationalAnnotationNames.Comment); RemoveAnnotation(ref annotations, RelationalAnnotationNames.ComputedColumnSql); RemoveAnnotation(ref annotations, RelationalAnnotationNames.IsFixedLength); RemoveAnnotation(ref annotations, ScaffoldingAnnotationNames.ColumnOrdinal); @@ -675,6 +676,13 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations) $"({_code.Literal(property.GetDefaultValueSql())})"); } + if (property.GetComment() != null) + { + lines.Add( + $".{nameof(RelationalPropertyBuilderExtensions.HasComment)}" + + $"({_code.Literal(property.GetComment())})"); + } + if (property.GetComputedColumnSql() != null) { lines.Add( diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs index c12c56d80e4..9c16caf8ad4 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs @@ -145,6 +145,27 @@ public void Plugins_work() scaffoldedModel.ContextFile.Code); } + [Fact] + public void Comments_use_fluent_api() + { + Test( + modelBuilder => modelBuilder.Entity( + "Entity", + x => + { + x.Property("Id"); + x.Property("Property") + .HasComment("An int property"); + }), + new ModelCodeGenerationOptions(), + code => Assert.Contains( + ".HasColumn(\"An int property\")", + code.ContextFile.Code), + model => Assert.Equal( + "An int property", + model.FindEntityType("Entity").GetProperty("Property").GetComment())); + } + private class TestCodeGeneratorPlugin : ProviderCodeGeneratorPlugin { public override MethodCallCodeFragment GenerateProviderOptions() diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs index 48f2d5b62b7..1e099903593 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs @@ -1801,6 +1801,36 @@ public void Unmapped_column_is_ignored() Assert.Equal(1, columns.Count); } + [Fact] + public void Column_comments() + { + var database = new DatabaseModel + { + Tables = + { + new DatabaseTable + { + Name = "Table", + Columns = + { + IdColumn, + new DatabaseColumn + { + Name = "Column", + StoreType = "int", + Comment = "An int column" + } + } + } + } + }; + + var model = _factory.Create(database, useDatabaseNames: false); + + var column = model.FindEntityType("Table").GetProperty("Column"); + Assert.Equal("An int column", column.GetComment()); + } + public class FakePluralizer : IPluralizer { public string Pluralize(string name)