0
votes

I currently have 2 projects setup - the first ia a .NET Core 3.0 API project and the second one is as well but just contains the EF Core models.

I have added a model called Country to the model project and when I try to add a API controller using EF actions for the Country model, I get the following error:

Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 StackTrace: at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_3.b__13() No parameterless constructor defined for type 'MyProject.Domain.Data.ApplicationDbContext'.

The ApplicationDbContext class is as follows:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    public DbSet<Country> Countries { get; set; }
}

I also get the following error message after the previous one:

No parameterless constructor defined for type 'MyProject.Domain.Data.ApplicationDbContext'

Any idea on what I am missing? I can add migrations and they run fine. I just can't add any API controllers to my API project.

1
I think you are scaffolding controller with a model. You can just try to create a controller class instead of scaffolding option. That works perfectly and you can customize the controller by your own wayNandhakumar Appusamy

1 Answers

0
votes

Go to API dependencies then add the second project,

Add the namespace in EF Core models.

namespace Sample.Core.Operations.SampleEF
{
 public class Request 
    { 
    }
}

Create the class like:

Core.Operations.SampleEF.Request request