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
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.
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).
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With