How do I generate EF Core migrations in a Visual Studio 2015 WinForms project?

会有一股神秘感。 提交于 2019-12-24 08:24:09

问题


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. 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.

  2. 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".

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

  4. 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/.

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?


回答1:


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

After executing the steps described in the question I have

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

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

  3. 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.

UPDATE:

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.



来源:https://stackoverflow.com/questions/42589884/how-do-i-generate-ef-core-migrations-in-a-visual-studio-2015-winforms-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!