Skip to content

Instantly share code, notes, and snippets.

@redwards510
Last active March 25, 2025 21:31
Uses EF Core Power Tools by ErikEJ (see link in code) to creates a .DGML class diagram (and serves it up for saving) of most of the EntityFrameworkCore (EF Core 2) entities in the ASP.Net MVC project when you go to yourwebsite/dgml. This is useful because there is no Class Diagram support in .Net Core 2 yet and it is difficult to find any kind o…
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace CHANGEME.Api.Controllers
{
[Route("Dgml")]
public class DgmlController : Controller
{
public CHANGEMEDbContext _context { get; }
public DgmlController( CHANGEMEDbContext context)
{
_context = context;
}
/// <summary>
/// Creates a DGML class diagram of most of the entities in the project wher you go to localhost/dgml
/// See https://github.com/ErikEJ/SqlCeToolbox/wiki/EF-Core-Power-Tools
/// </summary>
/// <returns>a DGML class diagram</returns>
[HttpGet]
public IActionResult Get()
{
System.IO.File.WriteAllText(Directory.GetCurrentDirectory() + "\\Entities.dgml",
_context.AsDgml(),
System.Text.Encoding.UTF8);
var file = System.IO.File.OpenRead(Directory.GetCurrentDirectory() + "\\Entities.dgml");
var response = File(file, "application/octet-stream", "Entities.dgml");
return response;
}
}
}
Copy link

ghost commented Jan 18, 2018

Very useful and perfectly working! Many thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment