entity-framework-coreasp.net-core-webapi

DbContextOptions error in ASP.NET Core Web API solution


Code:

public class RepositoryContext : DbContext
{
    public RepositoryContext(DbContextOptions options)
        : base(options)
    {
    }
}

enter image description here

error:

The type or namespace name 'DbContextOptions' could not be found (are you missing a using directive or an assembly reference?)
Repository D:\My Work\Algos\Repository\RepositoryContext.cs

enter image description here

I am trying to create a DbContext class here. Is there any issue? What is missing here? Do I need some namespaces also?

I am getting this error for the first time.


Solution

  • You referenced EntityFramework instead of EntityFrameworkCore.

    You need this package: https://www.nuget.org/packages/Microsoft.EntityFrameworkCore

    And this namespace: using Microsoft.EntityFrameworkCore;