Entity Framework Visual Studio 代码中的错误

Entity Framework error in Visual Studio Code

在 Visual Studio 代码中,我正在创建一个用 C# 编写的 Web-Api,我正在使用 Entity Framework 提供的各种功能,例如 DbContextOption 和 Dbset,但是当我使用 dotnet build 我收到以下消息:

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?)

这是发生错误的文件:

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;}
    }
 }

这是 csproj 文件:

<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. DbSet 大写 S
  2. 复数形式是DbContextOptions