### Add EFCommenter Package Source: https://github.com/roohial57/dotnetcomponent_efcommenter/blob/master/readme.md Install the EFCommenter NuGet package using the .NET CLI. ```bash dotnet add package EFCommenter ``` -------------------------------- ### Generated Migration Code with Comments Source: https://github.com/roohial57/dotnetcomponent_efcommenter/blob/master/readme.md Example of how EFCommenter automatically adds table and column comments to your migration file based on the XML documentation provided in your entity classes. ```csharp migrationBuilder.CreateTable( name: "People", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false, comment: "The full name of the person!!!"), Type = table.Column(type: "int", nullable: false, comment: "0: Admin | \n1: User | \n2: Guest | ") }, constraints: table => { table.PrimaryKey("PK_People", x => x.Id); }, comment: "The class declered a person!!!"); ``` -------------------------------- ### PostgreSQL Setup for EFCore Comments Source: https://context7.com/roohial57/dotnetcomponent_efcommenter/llms.txt EFCommenter works with Npgsql/PostgreSQL without additional configuration beyond using the Npgsql EF Core provider. Comments are written using PostgreSQL's COMMENT ON TABLE / COMMENT ON COLUMN DDL. ```csharp // Install: dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL var options = new DbContextOptionsBuilder() .UseNpgsql("Host=localhost;Database=myapp;Username=postgres;Password=secret") .Options; using var context = new AppDbContext(options); context.Database.EnsureCreated(); // Comments are written using PostgreSQL's COMMENT ON TABLE / COMMENT ON COLUMN DDL, // which is natively supported by Npgsql's EF Core migration generator. // The generated migration Up() method will include: // migrationBuilder.CreateTable( // name: "users", // columns: ..., // comment: "Represents a registered user account."); // migrationBuilder.AddColumn(..., comment: "The user's display name shown in the UI."); ``` -------------------------------- ### Add Entity Comments with EFCommenter Source: https://context7.com/roohial57/dotnetcomponent_efcommenter/llms.txt Define entities with XML doc summaries and register the EFCommenter extension in your DbContext's OnModelCreating method. This example demonstrates usage with SQL Server. ```csharp using EFCommenter; using Microsoft.EntityFrameworkCore; /// /// Represents a registered user account. /// public class User { public int Id { get; set; } /// /// The user's display name shown in the UI. /// public string Username { get; set; } = ""; /// /// The hashed password stored for authentication. /// public string PasswordHash { get; set; } = ""; /// /// Current account status. /// public UserStatus Status { get; set; } } /// /// Inactive: account is disabled. /// Active: account is fully operational. /// Banned: account has been suspended. /// public enum UserStatus { Inactive, Active, Banned } public class AppDbContext : DbContext { public AppDbContext(DbContextOptions options) : base(options) { } public DbSet Users => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { // Single call adds all entity and property comments modelBuilder.AddEntitiesComments(); } } var options = new DbContextOptionsBuilder() .UseSqlServer("Server=.;Database=MyApp;Trusted_Connection=True;TrustServerCertificate=True;") .Options; using var context = new AppDbContext(options); context.Database.EnsureCreated(); ``` ```csharp // After running `dotnet ef migrations add InitialCreate`, the generated migration will contain: // migrationBuilder.CreateTable( // name: "Users", // columns: table => new // { // Id = table.Column(nullable: false), // Username = table.Column(nullable: false, // comment: "The user's display name shown in the UI."), // PasswordHash = table.Column(nullable: false, // comment: "The hashed password stored for authentication."), // Status = table.Column(nullable: false, // comment: "0: Inactive | // 1: Active | // 2: Banned | ") // }, // constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }, // comment: "Represents a registered user account."); ``` -------------------------------- ### Enable XML Documentation Generation Source: https://github.com/roohial57/dotnetcomponent_efcommenter/blob/master/readme.md Configure your project to generate an XML documentation file by adding the GenerateDocumentationFile property to your .csproj file. ```xml true ``` -------------------------------- ### Design-Time Factory for EF Core Migrations Source: https://context7.com/roohial57/dotnetcomponent_efcommenter/llms.txt Implementing IDesignTimeDbContextFactory ensures migrations are generated correctly with comments when running `dotnet ef migrations add`, even without a live database. ```csharp using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; public class AppDbContextFactory : IDesignTimeDbContextFactory { public AppDbContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder(); // SQL Server optionsBuilder.UseSqlServer( "Server=.;Database=MyApp;Trusted_Connection=True;TrustServerCertificate=True;"); // PostgreSQL (uncomment to switch) // optionsBuilder.UseNpgsql("Host=localhost;Database=myapp;Username=postgres;Password=secret"); return new AppDbContext(optionsBuilder.Options); } } // Now running the following will generate a migration with all XML doc comments embedded: // $ dotnet ef migrations add InitialCreate // $ dotnet ef database update ``` -------------------------------- ### Entity and Enum with XML Comments Source: https://github.com/roohial57/dotnetcomponent_efcommenter/blob/master/readme.md Define your entity classes and enums with XML documentation comments. These summaries will be used to generate database comments. ```csharp /// /// The class declered a person!!! /// public class Person { public int Id { get; set; } /// /// The full name of the person!!! /// public string Name { get; set; } = ""; public PersonType Type { get; set; } } public enum PersonType { Admin, User, Guest } ``` -------------------------------- ### Integrate EFCommenter in DbContext Source: https://github.com/roohial57/dotnetcomponent_efcommenter/blob/master/readme.md Call the AddEntitiesComments extension method within your DbContext's OnModelCreating method to enable EFCommenter. ```csharp using EFCommenter; using Microsoft.EntityFrameworkCore; protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.AddEntitiesComments(); } ``` -------------------------------- ### Automatic Enum Column Comments Source: https://context7.com/roohial57/dotnetcomponent_efcommenter/llms.txt When a property's CLR type is an enum, EFCore automatically generates a formatted list of enum values with their integer codes and XML doc summaries. ```csharp /// Priority level for a support ticket. public enum TicketPriority { /// Can wait indefinitely. Low, /// Should be resolved within a week. Medium, /// Must be resolved within 24 hours. High, /// Production is down — act immediately. Critical } public class SupportTicket { public int Id { get; set; } public string Title { get; set; } = ""; public TicketPriority Priority { get; set; } // no summary needed on the property } // Resulting column comment on `Priority`: // "0: Low | Can wait indefinitely. // 1: Medium | Should be resolved within a week. // 2: High | Must be resolved within 24 hours. // 3: Critical | Production is down — act immediately." ``` -------------------------------- ### TPH Inheritance / Derived Entity Comments Source: https://context7.com/roohial57/dotnetcomponent_efcommenter/llms.txt For TPH inheritance, EFCore detects derived types and builds a composite table comment listing base and derived types. Property comments on shared columns are aggregated. ```csharp /// Base class for all payment methods. public abstract class Payment { public int Id { get; set; } /// Total amount charged in the transaction. public decimal Amount { get; set; } public string Discriminator { get; set; } = ""; } /// Payment made via credit or debit card. public class CardPayment : Payment { /// Last four digits of the card used. public string? CardLastFour { get; set; } } /// Payment made via bank wire transfer. public class WirePayment : Payment { /// IBAN of the source bank account. public string? IBAN { get; set; } } public class BillingDbContext : DbContext { public DbSet Payments => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.AddEntitiesComments(); } } // The `Payments` table comment will be: // "Payment | Base class for all payment methods.: // CardPayment | | Payment made via credit or debit card. // WirePayment | | Payment made via bank wire transfer. " // // The `CardLastFour` and `IBAN` column comments will include entity-level context: // "Entities: // CardPayment | Last four digits of the card used. | Payment made via credit or debit card. " ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.