Aymadoka.EfCoreMermaid
0.1.5-alpha
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 3.0
This package targets .NET Core 3.0. The package is compatible with this framework or higher.
This is a prerelease version of Aymadoka.EfCoreMermaid.
dotnet add package Aymadoka.EfCoreMermaid --version 0.1.5-alpha
NuGet\Install-Package Aymadoka.EfCoreMermaid -Version 0.1.5-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aymadoka.EfCoreMermaid" Version="0.1.5-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aymadoka.EfCoreMermaid" Version="0.1.5-alpha" />
<PackageReference Include="Aymadoka.EfCoreMermaid" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aymadoka.EfCoreMermaid --version 0.1.5-alpha
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Aymadoka.EfCoreMermaid, 0.1.5-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Aymadoka.EfCoreMermaid@0.1.5-alpha
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Aymadoka.EfCoreMermaid&version=0.1.5-alpha&prerelease
#tool nuget:?package=Aymadoka.EfCoreMermaid&version=0.1.5-alpha&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
该项目还在施工阶段,暂不可用
🛠️ EF Core ModelSnapshot 转 Mermaid ER 图工具
基于 Roslyn API 解析 EF Core ModelSnapshot 文件,自动生成 Mermaid 格式的 ER 图,助力数据库设计可视化。
🌟 项目简介
Aymadoka.EfCoreMermaid 是一个专注于 EF Core 项目的工具库,通过解析 Migrations 中的 ModelSnapshot 文件,利用 Roslyn 语法分析技术提取数据模型结构,最终生成可直接渲染的 Mermaid ER 图文本。
无论是团队协作中的数据模型沟通,还是重构时的模型梳理,该工具都能帮助开发者快速将代码中的数据模型转化为可视化图表,提升开发效率与项目可维护性。
🚀 核心功能
🔍 ModelSnapshot 解析
- 自动定位项目中的 ModelSnapshot.cs 文件
- 基于 Roslyn API 构建语法树,精准提取实体类定义
- 识别导航属性、主键、外键等关系映射
📊 Mermaid 生成
- 支持生成标准 Mermaid ER 图语法(mermaid graph格式)
- 自动映射实体关系(一对一、一对多、多对多)
- 包含属性类型、主键标识等详细元数据
⚙️ 灵活扩展
- 支持自定义命名空间过滤
- 可配置输出格式(缩进、关系线样式等)
- 预留钩子函数支持自定义实体转换逻辑
🛠️ 技术实现原理
🔗 Roslyn 语法分析流程
- 通过 SyntaxFactory 加载 ModelSnapshot.cs 文本
- 构建 SyntaxTree 并分析 ClassDeclarationSyntax
- 提取 PropertyDeclarationSyntax 中的属性定义
- 通过 IdentifierNameSyntax 解析导航属性关系
📉 Mermaid 生成逻辑
graph TD
A[实体类解析] --> B[属性提取]
A --> C[关系识别]
B --> D[生成实体节点]
C --> E[生成关系连线]
D & E --> F[组合Mermaid语法]
classDiagram
class Program {
+Main(args: string[])
}
class ConfigurationManager {
+LoadConfig(filePath: string): Config
+SaveConfig(config: Config, filePath: string)
}
class SnapshotParser {
+ParseSnapshotFile(filePath: string): ModelMetadata
+ParseSnapshotType(type: Type): ModelMetadata
}
class ModelMetadata {
-entities: List<EntityMetadata>
-relationships: List<RelationshipMetadata>
+AddEntity(entity: EntityMetadata)
+AddRelationship(relationship: RelationshipMetadata)
+GetEntities(): List<EntityMetadata>
+GetRelationships(): List<RelationshipMetadata>
}
class EntityMetadata {
-name: string
-properties: List<PropertyMetadata>
+AddProperty(property: PropertyMetadata)
+GetProperties(): List<PropertyMetadata>
+GetName(): string
}
class PropertyMetadata {
-name: string
-type: string
-isKey: bool
-isRequired: bool
+IsKey(): bool
+IsRequired(): bool
+GetName(): string
+GetType(): string
}
class RelationshipMetadata {
-sourceEntity: string
-targetEntity: string
-relationshipType: RelationshipType
-navigationProperty: string
+GetSourceEntity(): string
+GetTargetEntity(): string
+GetRelationshipType(): RelationshipType
+GetNavigationProperty(): string
}
class RelationshipType {
<<enumeration>>
+OneToOne
+OneToMany
+ManyToMany
}
class MermaidGenerator {
+GenerateDiagram(metadata: ModelMetadata): string
+SaveDiagram(diagram: string, filePath: string)
}
class ConsoleRenderer {
+RenderHelp()
+RenderSuccess(message: string)
+RenderError(message: string)
+RenderDiagramPreview(diagram: string)
}
Program --> ConfigurationManager : 使用
Program --> SnapshotParser : 使用
Program --> MermaidGenerator : 使用
Program --> ConsoleRenderer : 使用
SnapshotParser --> ModelMetadata : 创建
ModelMetadata --> EntityMetadata : 包含
ModelMetadata --> RelationshipMetadata : 包含
EntityMetadata --> PropertyMetadata : 包含
RelationshipMetadata --> RelationshipType : 使用
MermaidGenerator --> ModelMetadata : 读取
🧩 开源贡献
本项目遵循 MIT 开源协议,欢迎共建:
- ⭐️ 在 GitHub 上给项目点个 Star
- 📝 提交 Issues 反馈问题或需求
- 🚀 提交 Pull Request 贡献代码
- 📢 分享给更多使用 EF Core 的开发者
GitHub 地址:前往 GitHub
📬 联系方式
如有问题或建议,请在 GitHub 上提交 Issue 或联系我:
📧 Email: aymadoka@foxmail.com
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.0
- No dependencies.
-
.NETCoreApp 3.1
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
0.1.5-alpha | 113 | 7/9/2025 |
0.1.4-alpha | 115 | 7/9/2025 |
0.1.3-alpha | 118 | 7/3/2025 |
0.1.2-alpha | 108 | 6/26/2025 |
0.1.1-alpha | 114 | 6/26/2025 |