如何在Visual Studio 2015 WinForms项目中生成EF Core迁移? [英] How do I generate EF Core migrations in a Visual Studio 2015 WinForms project?

查看:160
本文介绍了如何在Visual Studio 2015 WinForms项目中生成EF Core迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在探索新的Entity Framework Core(不与ASP.Net结合使用,也不在Linux下,我所编码的只是一个经典的WinForms应用,该应用是在Windows 7 64位下使用SQLite作为数据库引擎在Visual Studio 7上构建的。 )。

I am exploring the new Entity Framework Core (NOT in conjunction with ASP.Net, nor under Linux, what I am coding is just a classic WinForms app built with Visual Studio under Windows 7 64-bit using SQLite as the database engine).


  1. 试图重现此示例我发现我需要 dotnet.exe 不属于Visual Studio 2015的工具,将与 .NET Core工具一起安装for Visual Studio

  1. Trying to reproduce this example I have found out that I need the dotnet.exe tool that is not a part of Visual Studio 2015 and to be installed with .NET Core tools preview for Visual Studio.

安装后,我遇到了另一个错误:尝试执行 dotnet ef迁移时,添加InitialCreate -c SqliteEfcExampleContext 未找到与命令 dotnet-ef匹配的可执行文件

After having installed it I have faced another error: while trying to execute dotnet ef migrations add InitialCreate -c SqliteEfcExampleContext: No executable found matching command "dotnet-ef".

然后我搜索了一条提示,说我需要安装 M带有NuGet的icrosoft.EntityFrameworkCore.Tools.DotNet

I have then Googled upon a hint saying I need to install Microsoft.EntityFrameworkCore.Tools.DotNet with NuGet.

它拒绝安装,说我需要更新版本的NuGet本身。所以我从 https://dotnet.myget.org/F/nuget-beta/vsix/ 更新了NuGet。

It refused to install saying I need a more recent version of NuGet itself. So I have updated NuGet from https://dotnet.myget.org/F/nuget-beta/vsix/.

但是我仍然无法安装 Microsoft.EntityFrameworkCore.Tools.DotNet -它表示`Severity Code Description Project文件行抑制状态错误包'Microsoft.EntityFrameworkCore.Tools.DotNet 1.1.0-preview4-final'具有项目类型'SqliteEfcExample'不支持的包类型'DotnetCliTool'。

But I still can't install Microsoft.EntityFrameworkCore.Tools.DotNet - it says `Severity Code Description Project File Line Suppression State Error Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.1.0-preview4-final' has a package type 'DotnetCliTool' that is not supported by project 'SqliteEfcExample'.

无论如何我如何创建迁移?

How do I create the migrations anyway?

推荐答案

我自己找到了答案,请允许我再次分享。 ..

I have found the answer myself, let me share it again...

执行问题中描述的步骤后,我有

After executing the steps described in the question I have


  1. 已安装 Windows Management Framework 5.0 以获取PowerShell

  1. Installed Windows Management Framework 5.0 to get PowerShell updated.

进入工具-NuGet软件包管理器-软件包管理器控制台以执行以下操作手动降低命令: PM>安装软件包Microsoft.EntityFrameworkCore.Tools -Pre

Went to Tools - NuGet Package Manager - Package Manager Console to execute the following command manually: PM> Install-Package Microsoft.EntityFrameworkCore.Tools -Pre.

然后我找到了相关的软件包管理器控制台命令(添加, Update-Database,Scaffold-DbContext等)正常工作,并使用 Add-Migration SqliteEfcExampleContext 为我已经编写的模型代码生成迁移代码。

Then I have found relevant Package Manager Console commands (Add-Migration, Update-Database, Scaffold-DbContext, etc.) working and used Add-Migration SqliteEfcExampleContext to generate the migration code for the model code I've already written.

更新:

继续,我遇到了另一个问题- ...违反了类型'TContext'的约束,试图使用上述命令。我已经在答案中描述了它和解决方案,以解决有关在稍微不同的上下文中发现的同一错误的问题。

The quest has continued and I have faced another problem - the ... violates the constraint of type 'TContext' error trying to use the above mentioned commands then. I have described it together with the solution in an answer to a question about the same error found in slightly different context.

这篇关于如何在Visual Studio 2015 WinForms项目中生成EF Core迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆