Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DbContext model diagram requires a parameterless contstructor #343

Closed
lamelyan opened this issue Jan 31, 2020 · 2 comments
Closed

DbContext model diagram requires a parameterless contstructor #343

lamelyan opened this issue Jan 31, 2020 · 2 comments

Comments

@lamelyan
Copy link

lamelyan commented Jan 31, 2020

Trying to generate a .dgml model diagram. When I select the option, I get an error that DbContext must have a parameterless constructor.

System.ArgumentException: Error:
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'CampaignContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
 ---> System.MissingMethodException: No parameterless constructor defined for type 'Repository.CampaignContext'.
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_3.<FindContextTypes>b__13()
   --- End of inner exception stack trace ---
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_3.<FindContextTypes>b__13()
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at ReverseEngineer20.EfCoreModelBuilder.BuildResult(String outputPath, Boolean generateDdl) in C:\Code\EFCorePowerTools\src\GUI\efpt\EFCoreModelBuilder.cs:line 39
   at ReverseEngineer20.Program.Main(String[] args) in C:\Code\EFCorePowerTools\src\GUI\efpt\Program.cs:line 44

Parameter name: processResult
   at EFCorePowerTools.Handlers.ModelAnalyzerHandler.Generate(String outputPath, Project project, GenerationType generationType) in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ModelAnalyzerHandler.cs:line 72

The parameterless constructor also requires that I set a connection to the database. This is probably because I use that connection string in the

  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseMySql(_connectionString);
        }

I would think that 'Add DbContext Model Diagram' wouldn't require connection to the database or parameterless constructor but just look at the model configuration.

The link provided in the exception message does say that the tools require a parameterless constructor but I wonder if there a workaround for this? I don't want to introduce code (parameterless constructor with a connection) that isn't required for my application.

Steps to reproduce

  1. Right-click on a project that contains DbContext
  2. Select Add DbContext Model Diagram

Further technical details

EF Core Power Tools version: 2.3.92.0

Database engine:
MySQL
Using package - Pomelo EF for MySql

Visual Studio version: (e.g. Visual Studio 2019 16.4.2)

@ErikEJ
Copy link
Owner

ErikEJ commented Jan 31, 2020

Did you read the link in the error message?

@ErikEJ
Copy link
Owner

ErikEJ commented Feb 5, 2020

I really dont think there is anything I can do here...

@ErikEJ ErikEJ closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants