Repository navigation
Description
When reverse engineering (scaffolding) a PostgreSQL database using dotnet ef dbcontext scaffold, comments applied to Views (COMMENT ON VIEW) are completely omitted from the generated code.
While column-level comments for views (COMMENT ON COLUMN) are successfully scaffolded as both XML documentation tags and .HasComment() fluent API calls, the view-level comments themselves are missing entirely from both the entity partial class and the OnModelCreating configuration. This issue specifically affects Views, whereas database Tables have their comments scaffolded correctly.
Steps to Reproduce
- Create a test database in PostgreSQL and execute the following SQL script to create a view with comments:
CREATE OR REPLACE VIEW public.test_view AS
SELECT 1 AS f1;
COMMENT ON VIEW public.test_view IS 'View description';
COMMENT ON COLUMN public.test_view.f1 IS 'Field description';- Run the EF Core scaffolding command:
dotnet ef dbcontext scaffold "Host=localhost; Port=5432; Database=test; Username=postgres; Password=xxx" Npgsql.EntityFrameworkCore.PostgreSQL --schema public --no-onconfiguring --forceActual Behavior
- Generated Entity Class (
TestView.cs): Contains XML documentation for the property, but lacks XML documentation for the class itself.
using System;
using System.Collections.Generic;
namespace Scaffolding.EF.Postgres;
// Missing XML documentation comment here ('View description')
public partial class TestView
{
/// <summary>
/// Field description
/// </summary>
public int? F1 { get; set; }
}- Generated DB Context (
TestDbContext.cs): Column configuration includes.HasComment(), but the view mapping lacks.HasComment().
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TestView>(entity =>
{
entity
.HasNoKey()
.ToView("test_view"); // Missing .HasComment("View description") here
entity.Property(e => e.F1)
.HasComment("Field description")
.HasColumnName("f1");
});
OnModelCreatingPartial(modelBuilder);
}Expected Behavior
The scaffolded entity class should include an XML summary tag containing the view description, and the fluent API configuration should include .HasComment("View description") chained to .ToView(), similar to how regular tables are processed:
/// <summary>
/// View description
/// </summary>
public partial class TestView { ... }entity
.HasNoKey()
.ToView("test_view")
.HasComment("View description");Environment / Technical Details
• PostgreSQL Version: 15.17
• Microsoft.EntityFrameworkCore.Design: 10.0.12
• Npgsql.EntityFrameworkCore.PostgreSQL: 10.0.3
• Target Framework: .NET 10 / ASP.NET Core 10
Activity
roji commentedon Oct 15, 2026
AI Triage
The below is an AI-generated analysis and may contain inaccuracies.
Confirmed. The comment is lost in EF Core's shared scaffolding pipeline, not in PostgreSQL metadata extraction. Classified this issue as Bug.
Reproduction and regression status
Executed a standalone console reproduction against PostgreSQL 18.4, using the SQL from this report and a commented table as a control:
In every case, both the class XML summary and view-level fluent configuration are missing, while column comments and the control table's comments are preserved.
This is not newly introduced by Npgsql 10.0.3 or EF Core 10: the previous patch combination and EF Core 9 also reproduce it. No earlier working version was identified, so an original regression boundary is not established. Updating to EF Core 10.0.13 does not resolve it.
The same metadata-to-generated-code failure also reproduces with SQL Server design-time services on EF Core 9.0.12, 10.0.12 and 10.0.13. That comparison uses an in-memory
DatabaseViewcontaining the comment; it does not connect to a SQL Server database. The executable repro below isolates that shared pipeline without requiring either database server.Cause and routing
Npgsql correctly populates
DatabaseView.Commentwith"View description"; this was verified during execution and matches the provider's metadata extraction code.In EF Core's
RelationalScaffoldingModelFactory.VisitTable, theDatabaseViewbranch only callsToView(...). Applyingtable.Commentoccurs exclusively in the non-view branch. Consequently, the scaffolded entity'sGetComment()is null. The entity template then has no comment to emit as XML documentation. The same view/table branching is still present in current EF Core source.Recommendation: close this provider issue in favor of reopening/tracking it in dotnet/efcore, with the repro below. This is not PostgreSQL-specific.
Duplicate search
No exact duplicate was found among open or closed EF Core issues. Related, but not duplicates:
minimal repro
Create a .NET 10 console project with these package references, replace
Program.cswith the following, and rundotnet run. No SQL Server instance is needed: the connection string is never opened, and the commented view metadata is supplied directly to the scaffolding model factory.The generated entity has a property XML summary containing
Field description, and its context contains.HasComment("Field description"). Neither generated file containsView description, despite that value being present on the inputDatabaseView.roji commentedon Oct 15, 2026
Duplicate of dotnet/efcore#39264
The shared EF Core scaffolding pipeline drops the view comment; the upstream issue includes a minimal reproduction.