我正在使用 EF Core 開發一個測驗 Web 專案。使用 DbContext 運行測驗時遇到以下問題。
以下是我的開發環境的資訊:
- ASP.NET 核心 3.1
- 物體框架核心 3.1
- IDE:Visual Studio 2019
- 平臺:Windows 10 PC
使用 Entity Framework Core 進行資料訪問的主要專案名稱OdeToFood和類別庫專案OdeToFood.Data。運行以下命令時,我收到以下錯誤訊息:
C:\Projects\OdeToFood\OdeToFood.Data>dotnet ef dbcontext info -s ..\odetofood\odetofood.csproj
構建開始...
構建成功。無法創建型別為“OdeToFoodDbContext”的物件。有關設計時支持的不同模式,請參閱
using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; namespace WebApplication1.Data { public class OdeToFoodDbContext : DbContext { public OdeToFoodDbContext() { } public OdeToFoodDbContext(DbContextOptions options) : base(options) { } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(@"...;"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Restaurant>().ToTable("Restaurant"); } public DbSet<Restaurant> Restaurats { get; set; } } public class Restaurant { [Key] public int Restaurats { get; set; } } }轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/394450.html
標籤:C# asp.net核心 网络 实体框架核心 数据库上下文

