'IServiceCollection' does not contains a definition for 'AddDbContext'

Viewed 36

I've installed EF 6.4.4 in my 'Service' project (class library).

In my 'WebApp' project (ASP.NET Core 6.0) I want to declare the DbContext in Program.cs. I've installed Microsoft.Extensions.DependencyInjection and added using Microsoft.Extensions.DependencyInjection; on top of the file then

var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connectionString));

Can't compile the project I have the following error :

'IServiceCollection' does not contains a definition for 'AdDbContext'

1 Answers
Related