0

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>
1
  • Looks like a typo: Wrong: DbContextOption, correct: DbContextOptions - note the "s" at the end of the class name and Dbset vs DbSet. You should see this error in visual studio too and not only when running dotnet build. See: learn.microsoft.com/en-us/dotnet/api/… Commented Sep 13, 2021 at 15:10

1 Answer 1

2
  1. It's DbSet with a capital S.
  2. It's DbContextOptions with plural form.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.