【问题标题】:entity framework enable-migrations no context type was found in the assembly实体框架 enable-migrations 在程序集中找不到上下文类型
【发布时间】:2021-08-31 19:04:39
【问题描述】:

我知道这个问题之前已经回答过了,但它仍然不适合我。我是第一次学习 ASP.NET 和 Entity Framework,我正在尝试启用迁移

这是我的项目结构

Models/DatabaseContext.cs

using Microsoft.EntityFrameworkCore;

namespace FileManager.Models
{
    public class DatabaseContext : DbContext
    {
        public DbSet<User> Users { get; set; }

        public DbSet<File> Files { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().ToTable("User");
            modelBuilder.Entity<File>().ToTable("File");
        }

    }
}

这些是我在包管理器中运行的命令:

Enable-Migrations

Enable-Migrations -ProjectName FileManager -StartupProject FileManager

他们都给我这个错误:在程序集“FileManager”中找不到上下文类型。

【问题讨论】:

    标签: c# asp.net entity-framework


    【解决方案1】:

    您可以尝试这样做 Enable-Migrations -Context DatabaseContext -Project FileManagerEnable-Migrations -ContextTypeName DatabaseContext -Project FileManager

    【讨论】:

      猜你喜欢
      • 2013-05-06
      • 1970-01-01
      • 2016-11-17
      • 1970-01-01
      • 2012-10-13
      • 2016-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多