迁移:程序集中未找到DbContext [英] Migration: No DbContext was found in assembly
问题描述
使用VS Community2017.我尝试创建初始迁移,并显示错误消息:
Using VS Community 2017. I have tried to create initial migration with error message saying:
同时安装了Entity Framework Core和Entity Framework 6.实体框架核心工具正在运行.对实体框架6使用'EntityFramework \ Add-Migration'. 在程序集"Test_Project"中找不到DbContext.确保使用正确的程序集,并且类型既不是抽象的也不是泛型的.
Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework\Add-Migration' for Entity Framework 6. No DbContext was found in assembly 'Test_Project'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
...我的dbcontext中的代码:
... code in my dbcontext:
protected override void OnModelCreating(DbModelBuilder mb)
{
base.OnModelCreating(mb);
mb.Entity<Stuff>().ToTable("Stuff");
}
public DbSet<Stuff> Stuff{ get; set; }
推荐答案
在程序包管理器控制台中,选择定义DbContext
的项目,然后运行命令add-migration initial
.
例如:public class SomeContext : DbContext
In the Package Manager Console select the project where the DbContext
is defined and run the command add-migration initial
.
For example:public class SomeContext : DbContext
这篇关于迁移:程序集中未找到DbContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!