-
-
Notifications
You must be signed in to change notification settings - Fork 300
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
Adding DbContext Model diagram showing errors #655
Comments
Did you check the link in the error message? I also have some tips in the wiki. |
Yes i have checked the link |
If it is still not working for you, I need a repro project. |
Here is the repo https://github.com/ersaumya/BlogPostApi |
Modifying the first part of your DbContext like this fixes the issue: public BlogPostContext()
{ }
public BlogPostContext(DbContextOptions<BlogPostContext> options) : base(options)
{ }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer("Data Source=.");
}
} |
@bricelam If if swap the order of the constructors, the DbContext discovery fails. Is that by design (so to speak) ? |
@ErikEJ Thanks for quick response its working now. Seems the order of constructors to be followed? |
Yes, that is what I am curious about. |
I'm also experiencing a similar issue. I was getting an exception similar to above, but I added a constructor that does not take any arguments to the DbContext class, and this error is resolved. After fixing that, at the bottom of the screen it says "An error occurred. See the output window for details." but there are no error messages in the output window and it does not generate the model. Please let me know if you need more info. |
@dfjackson what version of the extension? A repro project would help. |
I'm using version 2.5.692.0 of the extension. What is the easiest way to send you a repro project? |
@dfjackson you can email me at ejlskov at hotmail dot com |
Have you looked at the "Extensions" window, btw? |
I had not noticed the Extensions option in the Output window. Here's the exception I'm getting now in that window (which looks similar to the one above): System.ArgumentException: Error: Parameter name: processResult Parameter name: processResult Now I'm using extension version 2.5.744.0. I was able to upload a zip file of a solution that reproduces the issue: |
And the constructor ordering?? |
I will update the status bar message! |
@dfjackson I tried you repro, but your DbContext is crippled, and does not build. You are not using AddDbContext in your startup, I assume that is why design discovery fails. I think you can make the class library your startup project, and make it work if you add this to your DbContext: protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
optionsBuilder.UseSqlServer("Data Source=.");
}
} |
Sorry the repro was not completely working, but I got it working after adding the OnConfiguring method. The same thing fixed it in my real code too. Also I think updating the status bar message will help. Thanks! |
@dfjackson Thanks for the heads up and the good news! |
Adding DbContext Model diagram in my project getting errors
Steps to reproduce
Right click project > EF core power tools > Add DbContext model diagram
An error occured.See the output window for details
Output window error:
========== Build: 0 succeeded, 0 failed, 2 up-to-date, 0 skipped ==========
System.ArgumentException: Error:
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'BlogPostContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions
1[BlogPost.Infrastructure.DataContext.BlogPostContext]' while attempting to activate 'BlogPost.Infrastructure.DataContext.BlogPostContext'. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_4.<FindContextTypes>b__13() --- End of inner exception stack trace --- at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_4.<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 42
Parameter name: processResult
at EFCorePowerTools.Handlers.ModelAnalyzerHandler.d__2.MoveNext() in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ModelAnalyzerHandler.cs:line 78
Further technical details
EF Core Power Tools version: 2.5.277
Database engine: SQL Server
Visual Studio version:Microsoft Visual Studio Community 2019 Version 16.8.0
csproj file:
TargetFramework:net5.0
Microsoft.EntityFrameworkCore.Design Version="5.0.1"
Microsoft.EntityFrameworkCore.SqlServer Version="5.0.1"
Microsoft.EntityFrameworkCore.Tools Version="5.0.1"
The text was updated successfully, but these errors were encountered: