Fix:Unable to create an object of type DbContext For the different patterns supported at design time

preview_player
Показать описание
Unable to create an object of type DbContext For the different patterns supported at design time
Рекомендации по теме
Комментарии
Автор

in Program.cs add "var app = builder.Build();" this line after builder.Services.AddDbContex

victoriabarros
Автор

cannot create a dbset because this type is not included in the model context..
How to fix this?

logeshb
Автор

There might be an issue for the user that they have the configuration using the DI, also reinsure you have or (Tools will also add Design so both is fine) in your main project where the configuration is or.

In that case they just need to either:
1. Provide a default constructor to the DerivedDbContext.
2. Specifing the assembly reference inside the DI configuration using .MigrationsAssembly, like:
=> optionsBuilder

.UseSqlServer(_configuration.GetConnectionString("MulticheckDatabase"), options=>options.MigrationsAssembly("DB_CONTEXT_PROJECT_NAME"))

muhamedkarajic
Автор

If you are getting this error set your startup project to the API or WebApp project in my case my startup project name is API


if you are using the CLI is the startup flag -s ProjectName

codefactory
Автор

Put the below flags to point your persistence project and Startup project while in the root folder and it should work
dotnet ef migrations add InitialMigration -p Persistence/ -s API/

DiscipleW
Автор

not working ..already I am using the same thing AddTransient

eswar
Автор

This solution doesn't work for me, but thanks for sharing your knowledge.

edimilsonjosedasilvajunior
Автор

can u create a video 'invoice management system' with asp .net core 3.1

maroinecherif
Автор

But I need to use Scoped dbContext pool

ioniernestina
Автор

Didn't work in console application

aplb