In Visual Studio Code I am creating a Web-Api written in C # and I am using various functions that the Entity Framework offers such as the DbContextOption and Dbset, but when I use dotnet build I get the following messages:
Error CS0246: Namespace or type name 'Dbset <>' not found (is a using directive or assembly reference missing?) Error CS0246: The name of the type or namespace 'DbContextOption <>' was not found (is a using directive or assembly reference missing?)
This is the file where the error occurs:
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc;
using System.Data;
namespace web_api_db.Models{
public class Conexion : DbContext{
public Conexion(DbContextOption<Conexion> options) : base (options){}
public Dbset<Medicine> Medicine {get;set;}
}
}
And this is the csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.tools" Version="5.0.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.8" />
</ItemGroup>
</Project>
DbContextOption, correct:DbContextOptions- note the "s" at the end of the class name andDbsetvsDbSet. You should see this error in visual studio too and not only when running dotnet build. See: learn.microsoft.com/en-us/dotnet/api/…