跳到正文
Skillpedia
通用编程40k · #7187

efcore-d2-db-diagram

它能做什么

这个工具可以根据你项目的代码创建数据库的可视化图表。它能理解你使用 Entity Framework Core 定义数据表的方式,以及表与表之间的关系。

适用场景

  • ✓想查看数据库表之间如何关联的时候。
  • ✓需要为 C# 项目记录数据库结构的时候。
  • ✓想理解多对多等复杂关系的时候。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/efcore-d2-db-diagram/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/efcore-d2-db-diagram/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“使用 Entity Framework Core 为我的项目生成一张数据库图。”

每周 5 个新技能,1 分钟读完。

工作原理

工具会分析你使用 Entity Framework Core 编写的 C# 代码,查找数据表和字段的定义,以及它们之间的关系,然后据此绘制图表。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

EF Core D2 Database Diagram Generator

When to Use

Use this skill when the user wants to generate a database / ERD diagram from an Entity Framework Core codebase.

Typical requests:

  • Generate a D2 database diagram from EF Core entities.
  • Visualize tables, columns, primary keys, foreign keys and relationships.
  • Analyze DbContext, DbSet<T>, IEntityTypeConfiguration<T>, Fluent API and migrations.
  • Produce a .d2 file renderable to SVG/PNG with the d2 CLI.
  • Document the database model of an ASP.NET Core / .NET project.

Goal

Create a readable D2 entity-relationship diagram that reflects the actual EF Core persistence model, not only the raw C# class shape.

The diagram must prioritize:

  1. Database tables and relationships.
  2. Primary keys, foreign keys, required/optional columns.
  3. Owned types and value objects.
  4. Many-to-many relationships and join tables.
  5. Indexes, unique constraints and table names.
  6. EF Core conventions only when explicit mapping is absent.

Output is .d2 source code. It can be rendered to SVG or PNG via the d2 CLI.

Tools

  • d2 CLI: render .d2 files to SVG/PNG.
    • d2 input.d2 output.svg
    • d2 --layout=elk input.d2 output.svg
  • d2 fmt: format D2 files.
    • d2 fmt input.d2
  • No MCP server is required. The skill generates D2 source code as text.

Recommended Workflow

  1. Read the EF Core project structure.
  2. Locate all DbContext classes.
  3. Locate all DbSet<T> declarations.
  4. Locate entity classes, owned types, enum types and value objects.
  5. Read OnModelCreating and all IEntityTypeConfiguration<T> classes.
  6. Read migrations when available to confirm table names, join tables, indexes and delete behaviors.
  7. Build a normalized database model before writing D2.
  8. Ask the mandatory diagram questionnaire before generation.
  9. Generate the .d2 file using the database model, not raw class nesting.
  10. Validate D2 syntax with d2 fmt before delivery.
  11. Render with d2 --layout=elk schema.d2 schema.svg when possible.
  12. If regenerating, re-read EF Core mappings and migrations first.

Mandatory Questions Before Diagram Generation

Ask these questions for every new diagram and every regeneration unless the user already answered them in the same request.

  1. Which DbContext should be diagrammed? (auto-detect/all/specific name)
  2. Display columns? (all/key-only/none)
  3. Display column types? (Yes/No)
  4. Display nullable/required markers? (Yes/No)
  5. Display indexes and unique constraints? (Yes/No)
  6. Display enum values? (Yes/No)
  7. Display owned types? (inline/separate/hide)
  8. Display many-to-many join tables? (explicit/compact/hide)
  9. Display audit/technical tables? (Yes/No)
  10. Display migration-only tables not present as entities? (Yes/No)
  11. Which grouping mode? (bounded-context/schema/namespace/flat)
  12. Which layout engine? (elk/dagre/tala)
  13. Which output format? (d2/svg/png)

Default values, when the user asks for a quick generation:

  • DbContext: auto-detect
  • Columns: key-only
  • Column types: Yes
  • Nullable markers: Yes
  • Indexes: Yes
  • Enums: No
  • Owned types: inline
  • Join tables: explicit
  • Audit/technical tables: No
  • Migration-only tables: Yes
  • Grouping: bounded-context
  • Layout: elk
  • Output: d2

Reference Documents

Load these on demand when needed:

Reference When to load
references/efcore-model-extraction.md Rules for reading DbContext, DbSet, Fluent API, configurations and migrations
references/d2-erd-style.md D2 syntax and visual conventions for ERD diagrams
references/relationship-rules.md How to infer one-to-one, one-to-many, many-to-many and owned relationships
references/grouping-modes.md Rules for bounded-context, schema, namespace and flat grouping
references/quality-gate.md Final checklist before delivering the generated diagram

EF Core Extraction Rules

Source Priority

Use this priority order when sources disagree:

  1. Latest applied migration / migration snapshot.
  2. Fluent API configuration in OnModelCreating or IEntityTypeConfiguration<T>.
  3. Data annotations.
  4. EF Core conventions.
  5. Raw C# class shape.

Required EF Core Concepts to Detect

Detect and represent:

  • DbContext and DbSet<T>.
  • Entity class names and actual table names from ToTable.
  • Schema names from ToTable("Table", "schema").
  • Primary keys from HasKey, [Key], conventions and migrations.

…

常见问题

什么是 ERD 图?

ERD 是 Entity-Relationship Diagram(实体关系图)的缩写。它是一种图,用来展示数据库中的表以及表与表之间的关联。

什么是 Entity Framework Core?

它是一个帮助开发者在 C# 项目中操作数据库的工具,不需要手动编写大量 SQL 代码。

什么是 .d2 文件?

它是一个描述图表的文本文件。可以通过另一个名为 d2 CLI 的工具将其转换为 SVG 或 PNG 等图片。

详情

作者的原始描述

Generate D2 database diagrams from Entity Framework Core models. USE FOR: EF Core database diagram, Entity Framework Core ERD, DbContext diagram, C# entity relationship diagram, PostgreSQL schema visualization, generate .d2 file from EF Core entities, Fluent API mapping diagram, migrations-based database diagram, table relationships, owned types, many-to-many join tables, indexes and constraints.

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7187
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能