Skip to content

Inspect your DbContext model

Erik Ejlskov Jensen edited this page Nov 16, 2021 · 21 revisions

Add DbContext Model Graph

Adds a DGML graph of the DbContext(s) in you project, that allows you to inspect the relationships and properties on your DbContext Model.

View DbContext Model DDL SQL

Allows you to view the SQL CREATE script in order to create the current DbContext Model.

Challenges

Since the tool needs to load the compiled .dll based on your project and instantiate your derived DbContext(s), there can be a number of challenges preventing/blocking this:

  • You must be able to build the project 😄
  • Make sure you have the correct Startup project set in Visual Studio (should be the executable project or web app).
  • The model inspection tool (an external process launched by Visual Studio) can be blocked by a virus scanner or similar
  • The model inspection tool requires a compatible .NET Core runtime to be installed.
  • Your DbContext must be configured with a specific provider, or you will get this error: No database provider has been configured for this DbContext.
  • Your DbContext must have a parameter less constructor, see sample or make other design time helpers available.
  • If you cannot view the model graph, follow the advice here to install the viewer.

Working with .NET Standard 2.0 libraries

You cannot use the two features above with .NET Standard 2.0 libraries, as this project type does not produce any executable build output.

The following workarounds are available:

  • Target .NET Core 3.1 also:

<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>

(Notice the added "s"!) - TargetFrameworks

  • Use the AsDgml() extension method described below.

Add AsDgml() extension method

See the dedicated readme

Clone this wiki locally