efcore-d2-db-diagram

Generate D2 entity-relationship diagrams from Entity Framework Core models and migrations.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill efcore-d2-db-diagram
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: efcore-d2-db-diagram
Source: https://github.com/github/awesome-copilot/tree/main/skills/efcore-d2-db-diagram
Command: npx skills add https://github.com/github/awesome-copilot --skill efcore-d2-db-diagram

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Documenting the actual database schema behind an Entity Framework Core codebase requires manually tracing DbContext classes, Fluent API configurations, and migrations, which is slow and error-prone.

Core Features & Use Cases

  • EF Core Model Extraction: Reads DbContext, DbSet declarations, IEntityTypeConfiguration classes, Fluent API mappings, and migrations to build an accurate persistence model.
  • D2 Diagram Generation: Produces .d2 source files with sql_table nodes, cardinality-labeled edges, owned types, many-to-many join tables, indexes, and grouping by bounded context, schema, or namespace.
  • Configurable Output: A mandatory questionnaire controls column detail, nullable markers, enum display, technical table visibility, layout engine, and output format.
  • Use Case: A developer onboarding to a large ASP.NET Core project asks for an ERD of the main DbContext; the skill inspects the mappings and migrations, then delivers a renderable .d2 file plus the d2 CLI render command.

Quick Start

Ask the assistant to generate a D2 database diagram from the EF Core DbContext in this repository and render it to SVG.

Frequently Asked Questions about efcore-d2-db-diagram

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate an ERD diagram from Entity Framework Core entities?

Point the skill at your EF Core project and it reads the DbContext, DbSet declarations, Fluent API configurations, and migrations to build the persistence model. It then outputs a .d2 file you can render to SVG or PNG with the d2 CLI.

How to visualize EF Core many-to-many relationships in a database diagram?

The skill detects many-to-many relationships from UsingEntity calls, paired collection navigations, and migration-created join tables. It renders explicit join table nodes by default, marking implicit join tables created by EF Core conventions.

Does the diagram reflect Fluent API configuration or just C# classes?

It prioritizes the actual persistence model over raw class shape. The source priority is migrations and model snapshot first, then Fluent API, data annotations, EF Core conventions, and finally C# class structure.

Can I hide technical tables like __EFMigrationsHistory from the diagram?

Yes, technical tables such as __EFMigrationsHistory, Hangfire, ASP.NET Identity, audit, and outbox tables are hidden by default. When hidden, they are listed in the summary delivered alongside the diagram.

What tools are required to render the generated D2 diagram?

You need the d2 CLI installed to render and validate output. Use d2 fmt to check syntax and d2 --layout=elk input.d2 output.svg to render; the skill itself only generates D2 source text.

When should I not use this EF Core diagram approach?

Do not use it for runtime debugging, migration execution, schema deployment, or SQL performance tuning, as it only produces static documentation. It also does not generate draw.io diagrams, only D2 source files.