EntityFramework 7 - CodeFirst - SQLite - Manage DB using ApplyMigrations at runtime

entity-framework-core sqlite

Question

I am well on my way to utilizing EF7 CodeFirst with SQLite...but really want to employ DB Migrations at runtime. This is a desktop application (Click-once deployment) meant to sync with a main database when connection is available, and provide offline data when no connection is present.

I have pulled down the nuget pre-release versions and all is working, except I cannot find any documentation of how to apply the migrations at runtime. I can successfully Add-Migrations and manually Apply-Migrations...but need a way to programatically Apply-Migrations at runtime.

I've also browsed the EF7 open-source project, but could not get anywhere there.

Versions I'm using: Latest Pre-release as of 9/15/2015 EntityFramework.Sqlite v7.0.0-beta7 EntityFramework.Relational v7.0.0-beta7 EntityFramework.Commands v7.0.0-beta7 ...et al...you get the picture.

I am asking for help to apply runtime migrations...or what is the documented/recommended path for programatically maintaining a local/embedded db using EF7 CodeFirst SQLite?

UPDATE: I went back to EF6 with SQLite but then found out that there is not SQLMigrationGenerator for SQLite.

EDIT: I believe ApplyMigrations() method referenced in one of the notes has been deprecated. Searching the repository, there is no reference to "ApplyMigrations".

Popular Answer

Today you can invoke the extension method Migrate on the DatabaseFacade.

This method is only available when the using Microsoft.Data.Entity statement is present. It comes from the RelationalDatabaseFacadeExtensions class that is part of the EntityFramework.Relational package.

Still have to find out how to migrate up and down from the API.



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why