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

entity-framework-core visual-studio-2015

Question

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
1
3/3/2017 11:35:00 PM

Popular Answer

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.

1
5/23/2017 12:09:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow