1

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

faldeland
  • 587
  • 6
  • 20
  • possible duplicate of [How to apply migrations from code (EF7)](http://stackoverflow.com/questions/31710038/how-to-apply-migrations-from-code-ef7) – natemcmaster Sep 15 '15 at 22:57
  • SQLite is very limited when it comes to schema changes, but you can try the DevArt provider for EF6 – ErikEJ Sep 16 '15 at 05:45
  • Appreciate the info. I found that thread, but I'm afraid that they may have removed the runtime Apply-Migrations capability. Digging around in the GitHub repository, I found a reference to try Update-Database. Searching for this yielded some possibilities. I will investigate and report back. – faldeland Sep 16 '15 at 12:43
  • I can do what I need to do with SQLite at the level of migration management...so far. This has to be a target deployment for Entity Framework as many Windows 10 IoT devices, and desktop apps, are going to want an effective ORM like EF. – faldeland Sep 16 '15 at 12:46
  • 2
    `ApplyMigrations` was renamed to `Migrate`. – bricelam Oct 05 '15 at 15:41

1 Answers1

1

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.

riezebosch
  • 1,950
  • 16
  • 29
  • I'm also waiting for the ability to diff between applied migrations and ones that the current codebase needs. Without it, `EnsureDeleted()` can really only be used by catching known exceptions or during testing/early dev to mimic the old delete and recreate every time initializer. – JoeBrockhaus Apr 21 '16 at 16:43