【发布时间】:2018-05-15 21:08:32
【问题描述】:
我开始使用 EF Core 2.0, 我有一个针对 .NET 4.6.1 的控制台应用程序 我有一个非常简单的模型类,以及这个上下文:
public class ContextCore : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["efCoreCon"].ConnectionString);
}
public DbSet<ModelC> Models { get; set; }
}
这是连接字符串:
<add name="efCoreCon" connectionString="server=PC-MSHWF\SQLEXPRESS;database=efCoreDB;integrated security=true;" />
我注意到 official docs 的 ef 核心中没有 Enable-Migrations 的命令
所以我运行Add-migration firstMigration
但我收到了这个错误:
在程序集中找不到迁移配置类型 '新控制台'。 (在 Visual Studio 中,您可以使用 Enable-Migrations 来自包管理器控制台的命令以添加迁移 配置)。
当我尝试 Enable-Migrations 时,我收到了这个错误:
在程序集“NewConsole”中找不到上下文类型。
【问题讨论】:
-
您正在使用 EF 非核心命令。使用
dotnet ef ...。 -
你的上下文的命名空间是什么?
-
@PabloTondolodeVargas NewConsole.EFCore
-
我使用了
dotnet ef migrations add InitialCreate,但得到: dotnet : No executable found matching command "dotnet-ef"...
标签: c# ef-core-2.0