[英]Error running update-database entityframeworkcore 2
I have EntityFrameworkCore 2.0.2
installed in a class library on a solution containing an AspNet Core WebApi. 我在包含AspNet Core WebApi的解决方案的类库中安装了
EntityFrameworkCore 2.0.2
。
I have the following packages installed in the project; 我在项目中安装了以下软件包;
Microsoft.AspNetCore.Identity.EntityFrameworkCore - 2.0.2
Microsoft.AspNetCore.Identity.EntityFrameworkCore-2.0.2
Microsoft.EntityFrameworkCore - 2.0.2
Microsoft.EntityFrameworkCore-2.0.2
Microsoft.EntityFrameworkCore.SqlServer - 2.0.2
Microsoft.EntityFrameworkCore.SqlServer-2.0.2
Microsoft.Extensions.Identity.Stores - 2.0.2
Microsoft.Extensions.Identity.Stores-2.0.2
System.Data.SqlClient - 4.4.3
System.Data.SqlClient-4.4.3
My Class library project invokes the context as follows; 我的Class库项目按如下方式调用上下文;
public class MyContextFactory : IDesignTimeDbContextFactory<MyDataContext>
{
public MyContextFactory()
{
}
public MyDataContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<MyDataContext>();
builder.UseSqlServer(DbGlobals.DevDatabase);
return new MyDataContext(builder.Options);
}
}
I am getting the following error, when I try to run the update-database
command from the package manager console. 当我尝试从程序包管理器控制台运行
update-database
命令时,出现以下错误。
Application startup exception: System.IO.FileNotFoundException: Could not find file 'C:\\Users\\matt\\Source\\Repos\\project\\Services.WebApi\\bin\\Debug\\netcoreapp2.0\\ef.xml'.
应用程序启动异常:System.IO.FileNotFoundException:找不到文件'C:\\ Users \\ matt \\ Source \\ Repos \\ project \\ Services.WebApi \\ bin \\ Debug \\ netcoreapp2.0 \\ ef.xml'。
this now occurs when I try to add-migration
as well. 现在,当我尝试
add-migration
时也会发生这种情况。
I can't find any detail on ef.xml and how it is generated? 我找不到关于ef.xml及其生成方式的任何细节? Can anyone tell me what is going on here.
谁能告诉我这是怎么回事。
If I run an add-migration
i get the migration generated, but then get the error; 如果我运行
add-migration
我会生成迁移,但是会收到错误;
An error occurred while calling method 'BuildWebHost' on class 'Program'.
在类“程序”上调用方法“ BuildWebHost”时发生错误。 Continuing without the application service provider.
没有应用程序服务提供商就继续进行。 Error: Could not find file
'C:\\Users\\matt\\Source\\Repos\\project\\Services.WebApi\\bin\\Debug\\netcoreapp2.0\\ef.xml'.
错误:找不到文件
'C:\\Users\\matt\\Source\\Repos\\project\\Services.WebApi\\bin\\Debug\\netcoreapp2.0\\ef.xml'.
I have tried cleaning the project, re-compiling (there are no errors), I have also looked in the referenced folder and the file doesn't exist. 我尝试清理项目,重新编译(没有错误),我还查看了引用的文件夹,并且该文件不存在。 Nor (from a file search) has it been generated elsewhere?
也没有(通过文件搜索)是否在其他地方生成?
The migrations have been working fine now? 迁移现在工作正常了吗?
Per request my BuildwebHost
is; 根据请求,我的
BuildwebHost
是;
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
and I add EF in my Startup.cs; 然后在Startup.cs中添加EF;
services.AddDbContext<MyDataContext>(
options => options
.UseSqlServer(DbGlobals.DevDatabase));
The commands you are using update-database
and add-migration
don´t look like the supported Entity Framework Core CLI commands: 您正在使用的
update-database
和add-migration
命令看起来不像受支持的Entity Framework Core CLI命令:
dotnet ef add migrations <migration-name>
dotnet ef database update
Also check this SO question for further information: Entity Framework Core 2.0 add-migration not generating anything 还要检查此SO问题以获取更多信息: Entity Framework Core 2.0 add-migration不生成任何内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.