EF Core Diagram Class Generation and DbContext Visualization

The EF Core metadata model represents the structure of your data and the relationships between tables (entities) in your application. Put simply, it describes how entities in your application map to the underlying database. EF Core takes these models and uses them to build the underlying database schema and to translate queries between LINQ and SQL.

Although most models are universal and can work with any data store, they are also flexible enough to be customized for specific databases or application needs.

The ability to visualize these models is especially valuable. Specialized tools make it much easier for developers to build, customize, and manage EF Core models. One such tool is Devart Entity Developer – a powerful ORM designer for Entity Framework, Entity Framework Core, NHibernate, LinqConnect, Telerik Data Access, and LINQ to SQL.

Why visualize EF Core models?

Visualization allows you to convert abstract, complex systems into a visual form where entities, relationships, and constraints are easier to understand. Visualization is widely used in modern IDEs, and even experienced developers rely on visual tools for speed, accuracy, and clarity.

When working with EF Core models, visualization offers the following advantages:

  • Faster understanding of complex systems: A visual layout makes it much easier to see how elements are connected.
  • Improved communication: Diagrams help different specialists quickly understand and discuss the structure of the system. It also simplifies onboarding for new developers.
  • Easier debugging and refactoring: Visual representations reveal missing or incorrect relationships and constraints that might be harder to spot in code.
  • Better documentation: A model diagram reflects the current structure of the system. Maintaining such diagrams alongside the code helps ensure the documentation remains accurate.

Standalone or integrated with Visual Studio

Visual Studio is popular among developers because it offers powerful features, productivity tools, and visualization capabilities in one unified environment. In addition, it supports integration with third-party tools, allowing you to tailor the development experience to your specific needs.

Devart Entity Developer is fully integrated with Visual Studio 2008-2022 (including built-in documentation), which means you can design and manage your EF Core models directly inside your regular IDE. For those who prefer a different workflow, Entity Developer is also available as a standalone application, giving you the flexibility to work the way that suits you best.

Generate an EF Core diagram in Visual Studio

Let's explore the most common way to create an EF Core model with Entity Developer – using it directly within Visual Studio.

Launch the IDE and right-click somewhere in the Solution Explorer pane. Select Add > New Item from the menu.

Solution explorer add new item

Go to Installed > C# Items > Data, and select Devart EF Core Model. Click Add.

Go to Installed

In the Create Model Wizard, select Database First. Click Next.

Create Model Wizard

Fill in the details of the database connection (this tutorial uses a PostgreSQL database as a data source) and click Next.

Fill in the details of your database connection and click Next

Select Generate From Database and click Next.

Select Generate From Database and click Next

Choose the database objects to scaffold. You can select them all or only some of them. Click Next to proceed.

Choose the database object

Define the naming convention for the property names in the database object. We suggest keeping the default settings this time. Click Next.

EntityDeveloper Naming Rules

On the Model properties page, configure your model settings. Specify the target EF Core version compatible with the .NET Framework you are using in your project and the Target .NET Framework version. Once completed, click Next.

EntityDeveloper Model Properties

Choose the model diagram contents. You can use all entities, split the entities by database, or do a custom selection. For this tutorial, select All Entities and click Next.

EntityDeveloper Choose Diagram Contents

Choose the code generation templates. You can define different parameters for the object to follow. Let's use the default settings. Click Next.

EntityDeveloper Code Generation Templates

Your model is ready now. Click Finish.

EntityDeveloper Model Created

The newly created model opens.

EntityDeveloper Model Diagram

Entity Developer generates the entity classes and DbContext, and the model diagram displays all entities and their relationships visually.

Customize the diagram

EF Core diagrams created with Entity Developer are not static. You can edit them directly in the visual interface, without editing XML manually.

For convenience, you can reposition and resize entities, highlight areas for better diagram readability, add notes and comments, and manage the layout and settings in the process. These features make navigation and exploration much easier.

Right-click an entity to view the available options. For example, you can select Navigation Properties to display them directly in the model, as shown below.

Diagram Customized

Optimize your work with large models

Entity Developer not only generates accurate models for even the most complex database-driven applications, but also significantly simplifies working with them through the following features:

  • Multiple diagrams for a model, with each diagram containing a subset of entities
  • Diagram splitting, either manual or automatic
  • Entity grouping based on specific criteria
  • Object search within model diagrams
  • Diagram zooming for focusing on particular areas
  • Error messages and warnings for unused complex types or stored procedures
  • Pre-generation preview to speed up the execution of the first query

In addition, template-based automated code generation improves overall performance when working with large models, enabling you to manage all relevant aspects of each query efficiently.

Integration with online services

Powerful ADO.NET data providers from Devart's popular dotConnect product line make working with Entity Developer even more efficient. These providers enable you to directly connect to a wide range of data sources, including databases and online platforms such as Salesforce, Zoho, and Dynamics 365. You can work with data and perform data-related operations with ease.

Each dotConnect solution is tailored to the specific data source, supporting the unique features and capabilities of that source. Integration of both dotConnect providers and Entity Developer within Visual Studio makes the application development workflows smoother and helps you achieve better results faster.

Video tutorial

Conclusion

EF Core models are essential for developers working with C# and .NET. Visualizing these models and shifting key aspects of application development from pure coding into a visual environment can be invaluable. This approach simplifies many routine workflows and helps reduce errors, and tools like Entity Developer make it possible.

The combination of Entity Developer and dotConnect data providers offers a solution for developers and architects who aim for cleaner architecture and greater confidence with object-relational mapping (ORM). Both tools are available with fully functional free trials. Download and install dotConnect for your chosen data source, get Entity Developer to integrate with Visual Studio or use it as a standalone application, and experience improved productivity in your work!

Entity Developer

First-class visual ORM designer for .NET ORM frameworks with powerful code generation