efcore: db.Database.Migrate(); doesn't Work on EF Core 3.1.0 for UWP Project

I have been using EF Core 2.2.6 and EF Core Tool 2.2.6 in my UWP project. Now I want to use version 3.1.0. But I cannot migrate my SQLite db at app startup. I get error at db.Database.Migrate(); Can anyone help me with how to use EF Core v3.1.0 or 3.1.1 on the UWP project? I am ready to provide you more info if you need it.

My project details:

MusicPlayer10 (UWP project, version 16299) DataModel (.NET Standard v2.0, for SQLite model) MigrationStartup (.NET Core v2.2)

Further technical details

EF Core version: 3.1.0 Database provider: SQLite Target framework: UWP 16299 Operating system: Windows 10 (OS Build 18363.XX) IDE: Visual Studio 2019

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 40 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Note from team meeting: move this to the docs repo.

For anyone else that keeps their DbContext in a separate .NET Standard class library within a UWP solution, you will have to use:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    string dbPath =  Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), 
"myDatabaseName.db");
    optionsBuilder.UseSqlite($"Data Source={dbPath}");
}

We discussed this again and came to the following conclusions:

  • It doesn’t seem like UWP is going to make the current directory usable
  • We can make this work from the EF side
  • Therefore, even though we don’t want UWP-specific code in EF Core, in this case we will put it in order to let people get past at least this UWP limitation without major hassle.

We will target this for a 3.1.x patch release, although this will need approval.

@ajcvickers , Yes, I want full support for the UWP apps. And I want db.Database.Migrate() to work properly without explicitly defining the database location just like v 2.6.x.

Agreed; not being able to write to the current working directory is a pretty bad experience. Please submit UWP feedback here.

This is not UWP problem. It’s all about the EF Core problem. I cannot use ApplicationData in .NET Standard project if I use EF core 3.1.x and EF Core cannot migrate without explicit database file location.

Seems like EF Core and UWP are fighting with each other.

@bricelam I see similar issue on my UWP application too. Until 2.2.6, it works fine, but from 3.0.0 onwards, it fails. The only difference between what is reported vs what I see on my side is, for me, it fails to open the database.

It throws an error “SQLite Error 14: Unable to open database file”. Please find below the exact error.

image

Not sure if its the same error that @shakir820 is seeing on his side.

Any assistance is really appreciated. And if there is any additional details, required, please let me know that too. Thanks!!