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'
CodePudding user response:
The wrong package was added. EntityFramework 6.4.4 is the old EF library meant for .NET Framework applications, and knows nothing about the Dependency Injection middleware.
Use the Microsoft.EntityFrameworkCore package instead. The latest stable version is 6.0.8