Skip to content

Scaffolding drops view-level comments #39264

Closed

Description

@roji

Originally reported in npgsql/efcore.pg#3934.

Reverse engineering loses comments on views: the generated entity has no class XML summary, and the generated model configuration does not preserve the view comment. Column comments on the same view and comments on ordinary tables are preserved.

The comment is present on the input DatabaseView.Comment, but is lost when converting the database model to the EF model. This also reproduces using SQL Server design-time services, independently of Npgsql.

Minimal reproduction

Run dotnet run in a .NET 10 console project containing the following files. No database server is needed: this supplies a commented DatabaseView directly to the scaffolding pipeline, and the connection string is never opened.

Project file and Program.cs
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.12" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.12" />
  </ItemGroup>
</Project>
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using Microsoft.EntityFrameworkCore.SqlServer.Design.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

using var context = new TestContext();
var services = new ServiceCollection();
services.AddDbContextDesignTimeServices(context);
services.AddEntityFrameworkDesignTimeServices();
new SqlServerDesignTimeServices().ConfigureDesignTimeServices(services);
using var provider = services.BuildServiceProvider();

var database = new DatabaseModel { DatabaseName = "Repro", DefaultSchema = "dbo" };
var view = new DatabaseView
{
    Database = database,
    Schema = "dbo",
    Name = "test_view",
    Comment = "View description"
};
view.Columns.Add(new DatabaseColumn
{
    Table = view,
    Name = "f1",
    StoreType = "int",
    IsNullable = true,
    Comment = "Field description"
});
database.Tables.Add(view);

var model = provider.GetRequiredService<IScaffoldingModelFactory>()
    .Create(database, new ModelReverseEngineerOptions());
var options = new ModelCodeGenerationOptions
{
    ContextName = "TestDbContext",
    ModelNamespace = "Repro",
    ConnectionString = context.Database.GetConnectionString(),
    SuppressOnConfiguring = true
};
var code = provider.GetRequiredService<IModelCodeGeneratorSelector>()
    .Select(options).GenerateModel(model, options);
Console.WriteLine(code.AdditionalFiles.Single().Code);
Console.WriteLine(code.ContextFile.Code);

public class TestContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlServer("Server=unused;Database=Repro;Integrated Security=true")
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();
}

Actual: the generated entity contains the property XML summary Field description, and its context contains .HasComment("Field description"). Neither generated file contains View description. The scaffolded entity's GetComment() is null, despite the comment being present on the input view.

Expected: the view comment survives scaffolding, including the generated entity's XML documentation and corresponding model configuration, as table and column comments do.

Location of the loss

In RelationalScaffoldingModelFactory.VisitTable, the DatabaseView branch only calls ToView(...). Applying table.Comment occurs exclusively in the non-view branch. The entity template consequently has no entity comment to emit. The same branching is present in current main.

Versions verified

The database-independent SQL Server design-time repro above was executed on EF Core 9.0.12, 10.0.12, and 10.0.13, with the same result. No live SQL Server database was used.

The original PostgreSQL scenario was also executed against PostgreSQL 18.4 with Npgsql/EF Core Design 9.0.4/9.0.12, 10.0.2/10.0.11, 10.0.3/10.0.12, and 10.0.3/10.0.13. In each case, the provider reads DatabaseView.Comment correctly, but the shared scaffolding pipeline drops it; table and column comments are preserved. This is not newly introduced in EF Core 10. No earlier working version was identified.

Activity

  1. added theissue type on Oct 15, 2026
  2. reopened this on Oct 15, 2026
  3. reopened this on Oct 15, 2026
  4. added this to the 12.0-preview1 milestone on Oct 15, 2026
  5. added a commit that references this issue on Oct 15, 2026
    8ff6537
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions