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

Can't create Model Diagram #431

Closed
gurufordy opened this issue Jul 25, 2020 · 3 comments
Closed

Can't create Model Diagram #431

gurufordy opened this issue Jul 25, 2020 · 3 comments

Comments

@gurufordy
Copy link

Hi, I'm trying to visualise an existing DbContext and can't seem to get this working at all.

If I right click the project and select to view the Model Diagram, I get an error as below

System.ArgumentException: Error:
System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, IDbContextOptions contextOptions, DbContext context)
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
   at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
   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

But my DbContext has what it needs, as below:
image

VS 2019 Community 16.6.5
2.4.51 of the PT extension
EF Core 3.1.6
Connecting to Azure Cloud SQL

Anything I've missed, just ask, but what's going wrong?

@ErikEJ
Copy link
Owner

ErikEJ commented Jul 25, 2020

You need to add OnConfiguring with a UseSqlServer with a dummy connection string, as a bare minimum. Or use the Nuget package to create from a DbContext instance

@gurufordy
Copy link
Author

Erik, firstly I appreciate the quick response and getting your time. Keep up the good work!

I've seen the DGML Nuget package before, but I'm not great with exposing it outside of just right clicking in VS. I assumed it would ask me for a connstring on generation of the DGML, but will give the OnConfiguring a go now 👍

@gurufordy
Copy link
Author

Awesome that's working now thanks Erik!

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