Open doggy8088 opened 10 months ago
The mermaid script is intended to be used as a custom DbContext.t4
. We should mention this in the article.
How to put two DbContext.t4
in the same project? I want to generate both the context and the mermaid file.
You can't, but you can create a separate dummy project for the diagrams. Or just rename the files before generating.
You can with EF Core Power Tools
@ErikEJ Does EFCPT can handle multiple T4 templates other than DbContext.t4
and EntityType.t4
?
The mermaid sample from the doc seems not functional.
@doggy8088 Yes, both the VS and CLI editions support that, as documented here
The mermaid sample from the doc seems not functional.
A limitation in the MarkDown viewer?
The mermaid sample from the doc seems not functional.
A limitation in the MarkDown viewer?
No, it's a bug. I fixed as below:
<#@ output extension=".md" #>
<#@ assembly name="Microsoft.EntityFrameworkCore" #>
<#@ assembly name="Microsoft.EntityFrameworkCore.Relational" #>
<#@ assembly name="Microsoft.EntityFrameworkCore.Design" #>
<#@ parameter name="Model" type="Microsoft.EntityFrameworkCore.Metadata.IModel" #>
<#@ parameter name="Options" type="Microsoft.EntityFrameworkCore.Scaffolding.ModelCodeGenerationOptions" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="Microsoft.EntityFrameworkCore" #>
# <#= Options.ContextName #>
```mermaid
erDiagram
<#
foreach (var entityType in Model.GetEntityTypes().Where(e => !e.IsSimpleManyToManyJoinEntityType()))
{
#>
<#= entityType.Name #> {
}
<#
foreach (var foreignKey in entityType.GetForeignKeys())
{
#>
<#= entityType.Name #> <#= foreignKey.IsUnique ? "|" : "}" #>o--<#= foreignKey.IsRequired ? "|" : "o" #>| <#= foreignKey.PrincipalEntityType.Name #> : "<#= foreignKey.GetConstraintName() #>"
<#
}
foreach (var skipNavigation in entityType.GetSkipNavigations().Where(n => n.IsLeftNavigation()))
{
#>
<#= entityType.Name #> }o--o{ <#= skipNavigation.TargetEntityType.Name #> : <#= skipNavigation.JoinEntityType.Name #>
<#
}
}
#>
![image](https://github.com/dotnet/EntityFramework.Docs/assets/88981/5cc46098-b708-4e34-8089-3a13fa0a2a57)
Maybe a docs PR?
Maybe a docs PR?
Already done https://github.com/dotnet/EntityFramework.Docs/pull/4463
@doggy8088 Yes, both the VS and CLI editions support that, as documented here
@ErikEJ
I put a Docs/CodeTemplates/EFCore/DbContext.t4
file. How can I let ContosoUniversityContext.md
into Docs/
folder?
How can I let ContosoUniversityContext.md into Docs/ folder?
@doggy8088 Currently the files generated by DbContext.t4 are placed in same location as DbContext.cs, but I think it could be changed to the Docs folder. Please create an issue in EF Core Power Tools repo and I will investigate.
@doggy8088 I implemented a fix in the latest source, maybe you can test it from the latest master?
In the
Scaffolding other types of files
, you provided an T4 example, but not mentioned about the filename and where should I put it into. I don't know how to use this Mermaid T4 script.Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.