Search code examples
c#.netentity-frameworkasp.net-core

No DbContext was found in assembly 'project.api'


I have a .net core project which have multiple projects

project.api
project.data

my DbContext file is in project.data -> Context

when I am running. dotnet ef migrations add InitialCreate -o ../project.data I keep get the following error No DbContext was found in assembly 'project.api'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.

I have tried to add -c

dotnet ef migrations add InitialCreate -o ../project.data --context ../project.data.Context.DatabaseContext

I get the DbContext can't be found at project.data.Context.DatabaseContext

any suggestions ?


Solution

  • Well I think I add the DbContext in program.cs after

    // Add services to the container.
    
    builder.Services.AddControllers();
    // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
    builder.Services.AddEndpointsApiExplorer();
    builder.Services.AddSwaggerGen();
    

    which suppose to be before and I used the following command from the api directory

    dotnet ef migrations add IntialCreate -p ../project-data/project-data.csproj