Unable to add API Controller to .NET Core 3 API Project

.net-core entity-framework-core

Question

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
0
10/3/2019 2:30:21 PM

Popular Answer

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

0
10/4/2019 6:56:04 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow