Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create migrations with EF Core in Xamarin Android project

I tried to use EFCore with SQLite in a Xamarin.Android project. I also added the package Microsoft.EntityFrameworkCore.Tools. When I try to create database migrations I get various errors.

When running dotnet ef migrations add migrationname on the command line I get the error

No executable found matching command "dotnet-ef"

When running Add-Migration migrationname in Package Manager Console I get error

Startup project 'MyProject' targets framework 'MonoAndroid'. The Entity Framework Core Package Manager Console Tools don't support this framework.

Is there some way around this? Do I have to use EF6 instead of

like image 348
Mathias Rönnlund Avatar asked Feb 08 '18 15:02

Mathias Rönnlund


People also ask

How do I apply EF core migrations?

Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.

How do I add a migration to EF?

Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).

How do EF core migrations work?

EF Core compares the current model against a snapshot of the old model to determine the differences, and generates migration source files; the files can be tracked in your project's source control like any other source file. Once a new migration has been generated, it can be applied to a database in various ways.

Is EF core faster than EF6?

Entity Framework (EF) Core, Microsoft's object-to-database mapper library for . NET Framework, brings performance improvements for data updates in version 7, Microsoft claims. The performance of SaveChanges method in EF7 is up to 74% faster than in EF6, in some scenarios.


1 Answers

The guidance for unsupported frameworks is to move your DbContext code into a .NET Standard class library and use a dummy .NET Core console app with the tools.

cd MyDbContextProject
dotnet ef migrations add MyMigration --startup-project ..\MyDummyProject
like image 164
bricelam Avatar answered Sep 19 '22 20:09

bricelam