AspireC4.EntityFrameworkCore 17.0.0

dotnet add package AspireC4.EntityFrameworkCore --version 17.0.0
                    
NuGet\Install-Package AspireC4.EntityFrameworkCore -Version 17.0.0
                    
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="AspireC4.EntityFrameworkCore" Version="17.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AspireC4.EntityFrameworkCore" Version="17.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AspireC4.EntityFrameworkCore">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
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 AspireC4.EntityFrameworkCore --version 17.0.0
                    
#r "nuget: AspireC4.EntityFrameworkCore, 17.0.0"
                    
#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 AspireC4.EntityFrameworkCore@17.0.0
                    
#: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=AspireC4.EntityFrameworkCore&version=17.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AspireC4.EntityFrameworkCore&version=17.0.0
                    
Install as a Cake Tool

AspireC4.EntityFrameworkCore

NuGet version

A Roslyn source generator that records a project's Entity Framework Core model, including fluent OnModelCreating configuration, so the AspireC4 ER diagram can draw it at full fidelity.

This package is optional. It is a companion to AspireC4.Hosting.EntityFrameworkCore, which goes in the AppHost and does the drawing. Start there if you have not set up the ER diagram yet.

Why use it

Without this package, the AppHost reads your contexts from compiled metadata. That picks up conventions and data annotations, but fluent configuration lives in a method body, and method bodies are not in the metadata. Adding this package to the project that declares the DbContext captures that configuration.

Read from metadata only With this package
DbSet<T>, navigations, [Key], [Table], [Column], [Required], [MaxLength], [Index], … All of that, plus HasDefaultSchema, ToTable, HasKey, Ignore, HasIndex(...).IsUnique(), HasColumnName, HasColumnType, HasMaxLength, IsRequired, HasComment

Both read value objects the same way — Purview's [Scalar<T>], [Scalar(typeof(T))] and [Scalar("Name")], IScalarValueObject<,>, a bare [ValueObject], [ValueObject(EFMapping = Json)], EF's [ComplexType] and [Owned] — along with value-object collections and C# unions. The attributes matter here: a Purview generator writes the Value member into a generated file this analyzer cannot see, so a strongly-typed id is recognised by its [Scalar] attribute. See Value objects, enums and unions. | Fidelity: Approximate | Fidelity: Full |

It also records each entity's and property's description sources for the diagram's optional description column: [Description], [Display(Description = …)] and [DisplayName], the database comment, and the XML <summary>. The analyzer reads the summary straight from source, so unlike the metadata read it needs no documentation file. See ER Diagram Styling.

Requirements

  • netstandard2.0 analyzer, no runtime surface. The package ships under analyzers/dotnet/cs/, so it loads into the compiler for whatever framework your project targets and adds nothing to your build output. The generated [assembly: AspireC4EfModel] attribute is compiled into your own assembly, which the AppHost then reads.
  • The .NET 11 SDK to build the project. A source generator runs inside the compiler, and this one is built against Roslyn 5.9 — the project's target framework has no bearing on it. An older SDK reports CS9057 and skips the generator, so the ER diagram falls back to the approximate metadata read. See the requirements page.
  • The project still has to be registered in the AppHost with AddProject<Projects.X>(...), and the AppHost still has to call WithEntityFrameworkDiagram().

Installation

Add it to the project that declares your DbContext. That can be the service project or a class library it references. Do not add it to the AppHost.

dotnet add package AspireC4.EntityFrameworkCore

That is the whole opt-in. There is no code to write and nothing to configure. The package is a development dependency (PrivateAssets="all"), so it does not flow to the projects that reference yours:

<PackageReference Include="AspireC4.EntityFrameworkCore" PrivateAssets="all" />

How it works

At compile time the generator analyses every DbContext in the project and emits the model as a single assembly attribute, [assembly: AspireC4EfModel("<json>")]. The AppHost reads that attribute straight from the built assembly's metadata. None of your code is loaded or run.

  • No runtime dependency. The package adds no assembly to your output, only the attribute in your own assembly.
  • No files written. The generator only adds source, so builds stay deterministic and incremental.

Diagnostics

All are Info. They point out where the diagram may be incomplete.

ID Meaning
ASPIREC4008 A DbContext was found but no entity types could be discovered
ASPIREC4009 An entity type has no discoverable primary key
ASPIREC4010 Configuration could not be interpreted statically, e.g. ApplyConfigurationsFromAssembly

Configuration applied indirectly, such as IEntityTypeConfiguration<T> classes loaded with ApplyConfigurationsFromAssembly, cannot be seen by a source generator. If you rely on it, use AspireC4.EntityFrameworkCore.ModelDump, which builds the real model at build time.

More information

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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
17.0.0 111 11/26/2026
17.0.0-prerelease.4 63 11/22/2026
17.0.0-prerelease.3 66 11/21/2026
17.0.0-prerelease.2 70 11/20/2026
17.0.0-prerelease.1 60 11/19/2026
13.6.5 98 11/16/2026
13.6.5-preview.1 65 11/12/2026
13.6.4-preview.3 68 11/8/2026
13.6.4-preview.2 74 10/31/2026
13.6.4-preview.1 76 10/29/2026
13.6.0-preview.4 68 10/27/2026
13.6.0-preview.3 73 10/24/2026
13.6.0-preview.2 73 10/22/2026
13.6.0-preview.1 78 10/18/2026