AspireC4.Hosting.EntityFrameworkCore
13.6.4-preview.3
See the version list below for details.
dotnet add package AspireC4.Hosting.EntityFrameworkCore --version 13.6.4-preview.3
NuGet\Install-Package AspireC4.Hosting.EntityFrameworkCore -Version 13.6.4-preview.3
<PackageReference Include="AspireC4.Hosting.EntityFrameworkCore" Version="13.6.4-preview.3" />
<PackageVersion Include="AspireC4.Hosting.EntityFrameworkCore" Version="13.6.4-preview.3" />
<PackageReference Include="AspireC4.Hosting.EntityFrameworkCore" />
paket add AspireC4.Hosting.EntityFrameworkCore --version 13.6.4-preview.3
#r "nuget: AspireC4.Hosting.EntityFrameworkCore, 13.6.4-preview.3"
#:package AspireC4.Hosting.EntityFrameworkCore@13.6.4-preview.3
#addin nuget:?package=AspireC4.Hosting.EntityFrameworkCore&version=13.6.4-preview.3&prerelease
#tool nuget:?package=AspireC4.Hosting.EntityFrameworkCore&version=13.6.4-preview.3&prerelease
AspireC4.Hosting.EntityFrameworkCore
Adds a live ER diagram of your Entity Framework Core DbContext types to an
Aspire AppHost, alongside the
AspireC4 architecture diagram and linked from it.
It is optional and additive: the architecture diagram from AddAspireC4() is always the base, and
WithEntityFrameworkDiagram() adds the ER diagram beside it. You can run the architecture diagram on its
own without this package; there is no way to have the ER diagram without it, because the extension hangs
off the builder AddAspireC4() returns.
You install it in the AppHost and call one method. Your service projects need no changes.
Prerequisites
- .NET 10 or later. This package targets
net10.0; the optionalAspireC4.EntityFrameworkCoreanalyzer isnetstandard2.0and theAspireC4.EntityFrameworkCore.ModelDumptool isnet10.0. - An Aspire 13.5+ AppHost already using
AspireC4.Hosting(this package depends on it, so installing this one brings it in). - The projects that own your
DbContexttypes are registered in the AppHost withAddProject<Projects.X>(...). - Docker (or Podman) for the default viewer sidecar. See Without a container runtime if you have neither.
Container image exports verify bind sharing through Purview.Containers.Environment; preload
alpine:3.19 offline or set CONTAINER_ENVIRONMENT_PROBE_IMAGE. For WSL or shared remote
daemons, install Purview.Containers.Aspire and call builder.AddContainerEnvironment()
to adapt the viewer sidecar's mounts as well. See the
container environment guide
for mapping configuration, marker write permissions and remote-host limitations.
Enabling DbContext modelling
1. Add the package to the AppHost
dotnet add package AspireC4.Hosting.EntityFrameworkCore
2. Register the projects that own your DbContext types
The diagram is built from Aspire project resources. Every project you add with AddProject is
scanned for DbContext types, including contexts that live in class libraries the project references.
A project that is only a <ProjectReference>, or that runs as a container or executable, is not scanned.
<ItemGroup>
<ProjectReference Include="..\Orders.Api\Orders.Api.csproj" />
</ItemGroup>
3. Call WithEntityFrameworkDiagram()
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAspireC4()
.WithEntityFrameworkDiagram();
builder.AddProject<Projects.Orders_Api>("orders-api");
builder.Build().Run();
Run the AppHost. The dashboard shows an aspirec4-er resource with a View ER Diagram link, and
each project that contributed a context gets an ER Diagram link. The project's element in the
architecture diagram gets one too. Output is written to ./.aspirec4/erd/ beside the AppHost.
The model is read from each project's build output (bin/), so a project must have been built
before the AppHost starts. Building the AppHost builds its referenced projects, so normally you do not
need to do anything.
4. (Optional) Increase fidelity
Without any change to your services, the model is recovered from assembly metadata. That covers
conventions and data annotations but not fluent OnModelCreating configuration, because a method
body is not in the metadata. Two opt-in packages close that gap. Each is enabled just by adding the
package reference:
| Add this package | To this project | And you get |
|---|---|---|
| (nothing) | — | Approximate: DbSet<T>, navigations, data annotations, EF naming conventions |
AspireC4.EntityFrameworkCore |
The project that declares the DbContext |
Full: adds fluent configuration (ToTable, HasKey, HasIndex, HasColumnName, …) |
AspireC4.EntityFrameworkCore.ModelDump |
The project that references the EF Core provider and has an IDesignTimeDbContextFactory<T> |
Full: the real EF IModel, with value converters and composite foreign keys |
# In the project that declares the DbContext
dotnet add package AspireC4.EntityFrameworkCore
# In the project that owns the EF Core provider and a design-time factory
dotnet add package AspireC4.EntityFrameworkCore.ModelDump
When a context is available from more than one source, the best one is used: dump, then descriptor, then metadata. Each context in the diagram records its fidelity, so an approximate model is never mistaken for a complete one.
Screenshots

The image above is captured from the sample AppHost in the
repository and stored in docs/images/screenshots/. Your own
diagram exports to ./.aspirec4/images/ on startup (ExportImages, SVG and PNG by default), and the
viewer has its own Save as SVG / PNG buttons.
Choosing which contexts appear
By default every project resource is scanned. To narrow that down:
builder.AddAspireC4()
.WithEntityFrameworkDiagram(configure: options => options
.WithProjectOptInOnly() // only projects marked below
.WithExcludedContexts("IdentityDbContext")); // short or fully-qualified name
builder.AddProject<Projects.Orders_Api>("orders-api")
.WithEntityFrameworkModel(options => options
.WithIncludedContexts("OrdersDbContext")); // per-project filter
builder.AddProject<Projects.Billing_Api>("billing-api")
.WithEntityFrameworkModel(label: "Billing"); // label the project's group
Names match case-insensitively, and an exclusion always wins over an inclusion. A context that reaches the diagram through several projects is shown once.
Renderers
Renderer |
Output | Use it for |
|---|---|---|
Interactive (default) |
.json + a browser viewer |
Exploring the schema: search, column-level edges, crow's-foot cardinality, PNG/SVG export |
Mermaid |
.mmd + preview |
Pasting into GitHub, Azure DevOps or a wiki |
Dbml |
.dbml |
dbdiagram.io and other DBML tooling |
D2 |
.d2 + a live d2 --watch sidecar |
A live d2 view |
builder.AddAspireC4()
.WithEntityFrameworkDiagram(configure: options => options.Renderer = ErdRenderer.Mermaid);
The interactive and Mermaid viewers are static files served by a small nginx sidecar, so the
dashboard has a real URL to link to. Their JavaScript ships inside this package and works offline.
Configuration
Set options in the configure callback or in the AspireC4:EntityFramework configuration section.
| Property | Default | Description |
|---|---|---|
Renderer |
Interactive |
Interactive, Mermaid, Dbml or D2 |
Title |
null |
Title shown in the diagram |
DiscoverAllProjects |
true |
Scan every project resource. WithProjectOptInOnly() restricts this to projects marked with WithEntityFrameworkModel() |
IncludedContexts / ExcludedContexts |
empty | WithIncludedContexts(...) / WithExcludedContexts(...) |
OutputDirectory |
"./.aspirec4/erd/" |
Where generated files are written, relative to the AppHost |
FileName |
"schema.gen" |
Generated file name without extension |
DomainTypeDisplay |
DomainTypeFirst |
How value objects and enums appear beside the store type: AssetId (guid), ActorType (int, enum) |
ShowNullability |
true |
Mark nullable columns with ? |
GroupBySchema / GroupByContext |
true |
Group tables by database schema, and by DbContext when there are several |
UseSubgraphs |
true |
Mermaid only: one subgraph per DbContext (Mermaid 11.17+) |
LayoutEngine |
Elk |
D2 only: Dagre, Elk or Tala |
UseViewerServer |
true |
Serve the viewer from a container. Set false where there is no container runtime |
HideFromDashboard |
false |
Hide the diagram's sidecar from the dashboard |
ExportImages |
true |
Write schema.svg / schema.png to ./.aspirec4/images/ when the model changes |
ImageFormats |
{Svg, Png} |
WithImageExport(...), or WithoutImageExport() to turn export off |
UseViewerFidelityExport |
false |
Render images through the interactive viewer in a headless browser. Pulls a ~3.7 GB Playwright image |
D2Command |
null |
A local d2 binary for image export, instead of the container |
ContainerRuntimeCommand |
"docker" |
Set to podman where Aspire uses Podman |
Set OutputDirectory in the callback rather than in configuration. The sidecar's bind mount is fixed
when the AppHost builder runs, so a value from configuration changes where files are written but not
what the sidecar serves.
Without a container runtime
// Generate the files without starting a viewer container, and render images with a local d2
builder.AddAspireC4()
.WithEntityFrameworkDiagram(configure: options =>
{
options.UseViewerServer = false; // the dashboard offers an "open locally" command instead
options.D2Command = "d2"; // or call options.WithoutImageExport()
});
// Or, with the D2 renderer, replace the d2 container with a local binary
builder.AddAspireC4()
.WithEntityFrameworkDiagram(configure: options => options.Renderer = ErdRenderer.D2)
.WithLocalD2CLI(); // must come after WithEntityFrameworkDiagram
d2 is a Go binary. Install it with scoop, Homebrew, install.sh or go install.
Troubleshooting
- No diagram content. Check the project is added with
AddProject<Projects.X>and has been built. Theaspirec4-erresource's log names each project where no model was found. - Tables are missing their fluent configuration. The context was read from metadata
(
Approximate). AddAspireC4.EntityFrameworkCoreto the project that declares it. - A composite or fluent-only relationship is not drawn. Only the model dump sees these. Add
AspireC4.EntityFrameworkCore.ModelDumpto the project with the provider and a design-time factory. - Not captured from any static source: owned types, inheritance mapping, delete behaviour,
sequences, check constraints. Relationships across
DbContextboundaries are never drawn.
More information
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Aspire.Hosting (>= 13.6.4)
- AspireC4.Hosting (>= 13.6.4-preview.3)
- Purview.Containers.Environment (>= 1.0.0-prerelease.10)
- System.Reflection.MetadataLoadContext (>= 10.0.14)
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 |
|---|---|---|
| 17.0.0 | 92 | 11/26/2026 |
| 17.0.0-prerelease.4 | 102 | 11/22/2026 |
| 17.0.0-prerelease.3 | 71 | 11/21/2026 |
| 17.0.0-prerelease.2 | 95 | 11/20/2026 |
| 17.0.0-prerelease.1 | 114 | 11/19/2026 |
| 13.6.5 | 390 | 11/16/2026 |
| 13.6.5-preview.1 | 92 | 11/12/2026 |
| 13.6.4-preview.3 | 78 | 11/8/2026 |
| 13.6.4-preview.2 | 114 | 10/31/2026 |
| 13.6.4-preview.1 | 88 | 10/29/2026 |
| 13.6.0-preview.4 | 76 | 10/27/2026 |
| 13.6.0-preview.3 | 95 | 10/24/2026 |
| 13.6.0-preview.2 | 70 | 10/22/2026 |
| 13.6.0-preview.1 | 117 | 10/18/2026 |