Last active
March 11, 2022 15:25
-
-
Save redwards510/a26276218be2b9d104e5e590ebed5b92 to your computer and use it in GitHub Desktop.
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very useful and perfectly working! Many thanks for sharing!