GithubHelp home page GithubHelp logo

evalex / ef-db-diagrams Goto Github PK

View Code? Open in Web Editor NEW
60.0 5.0 26.0 1.48 MB

Visualize model created with EntityFramework Core

Home Page: https://db-diagrams.firebaseapp.com/

License: MIT License

C# 16.06% CSS 5.83% JavaScript 0.41% TypeScript 71.85% HTML 5.85%
entityframeworkcore aspnetcore diagram

ef-db-diagrams's Introduction

EntityFrameworkCore.Diargams

Visualize model created with EntityFramework Core in ASP.NET Core app.

https://db-diagrams.firebaseapp.com/

Installation

  1. Install NuGet package EntityFrameworkCore.Diagrams
  2. Use AddEfDiagrams() extension method in Configure() method of your Startup class to add middleware. Specify your DbContext type instead of ApplicationDbContext in the following example: app.AddEfDiagrams<ApplicationDbContext>(); Here's how your Configure() method might look like after this step (notice commented line):
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
  loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  loggerFactory.AddDebug();

  if (env.IsDevelopment())
  {
      app.UseDeveloperExceptionPage();
      app.UseBrowserLink();
      app.AddEfDiagrams<ApplicationDbContext>();  //  <-- Here's the config for EntityFrameworkCore.Diargams
  }
  else
  {
      app.UseExceptionHandler("/Home/Error");
  }

  app.UseStaticFiles();

  app.UseMvc(routes =>
  {
      routes.MapRoute(
          name: "default",
          template: "{controller=Home}/{action=Index}/{id?}");
  });
}
  1. Start your app and browse to /db-diagrams page. You should see the diagram now.

Notice that the middleware is added only in Development mode. This is important! Otherwise, any user in Production will se your model structure, which may not be desireable. This is not the case if you are developing public API, though.

Contributing

Feel free to report any bugs or feature requests - just create an issue. Contributions are appreciated!

License

MIT

ef-db-diagrams's People

Contributors

evalex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ef-db-diagrams's Issues

Mouse edge pan

Hovering mouse in edge hotzone for prolonged period should pan viewport (scroll). Quick passing through hotzone should be ignored

System.IO.DirectoryNotFoundException

Full stacktrace:

System.IO.DirectoryNotFoundException
  HResult=0x80070003
  Message=C:\Users\xxxx\Documents\GitHub\xxxx\src\xxxx\EntityFrameworkCore.Diagrams\wwwroot\db-diagrams\
  Source=Microsoft.Extensions.FileProviders.Physical
  StackTrace:
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
   at Microsoft.Extensions.DependencyInjection.EfDiagramsOptions..ctor()
   at Microsoft.Extensions.DependencyInjection.EfDiagramsServiceCollectionExtensions.AddEfDiagrams[TDbContext](IApplicationBuilder app)
   at ThePubInn.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\xxxx\Documents\GitHub\xxxx\src\ThePubInn\ThePubInn\Startup.cs:line 54
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)

Configure method code snippet:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.AddEfDiagrams<StoreContext>();
            }

AspNetCore 3.1
NuGet package version 3.1

StackOverflow with self-referencing entities

An entity like this will cause a StackOverflow.

    public class Project
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

        public Guid? ParentId { get; set; }
        public Project Parent { get; set; }

        public ICollection<Project> Children { get; set; }
}

`System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior'

I can't see any diagram. When I go to /db-diagram I get the following exception. It seems to have something to do with Json serialization within the project. My model seems ok, and I tried adding this configuration option to ConfigureServices() on Startup.cs

services.AddMvc()
    .AddJsonOptions(opts => {
        // Force Camel Case to JSON
        opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        // this is key to preventing cyclical infinite loops with your entities and navigation properties. 
        opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; 
    });

Maybe my model is somehow incorrect, but i can't figure out what the offending Entity Is. Any ideas? The exception is thrown in the Static Files middleware.

System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior' from assembly 'Microsoft.EntityFrameworkCore, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
   at System.Reflection.RuntimeMethodInfo.GetParameters()
   at Newtonsoft.Json.Serialization.DefaultContractResolver.GetCallbackMethodsForType(Type type, List`1& onSerializing, List`1& onSerialized, List`1& onDeserializing, List`1& onDeserialized, List`1& onError)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveCallbackMethods(JsonContract contract, Type t)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver.ResolveContract(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteStartArray(JsonWriter writer, Object values, JsonArrayContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at Microsoft.Extensions.DependencyInjection.EfDiagramsMiddleware.<GetModel>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Extensions.DependencyInjection.EfDiagramsMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.