faldeland
faldeland

Reputation: 587

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

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

Upvotes: 1

Views: 1393

Answers (1)

riezebosch
riezebosch

Reputation: 2018

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.

Upvotes: 1

Related Questions