General way to switch between Sqlite or SqlServer in EF Core?

asp.net-core entity-framework-core sql-server system.data.sqlite

Question

I want to be able to switch on the fly between using SQLite and SqlServer as a db provider for Entity Framework in an ASP.NET Core app.

The usual pattern to associate a DbContext with a Database Provider is via code in the ConfigureServices method:

        services.AddDbContext<FeedbackDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("Feedback")));

Each of the database providers for EF Core adds its own extension method as Use<Provider>.

It is surprising to me that I can't find a way to specify the database provider for a connection string in config

1
1
12/7/2018 11:43:30 AM

Popular Answer

You should be able to just change:

from:

services.AddDbContext<FeedbackDbContext>(
    options => options.UseSqlite(Configuration.GetConnectionString("Feedback")));

to:

services.AddDbContext<FeedbackDbContext>(
    options => options.UseSqlServer(Configuration.GetConnectionString("Feedback")));
0
2/2/2019 1:16:13 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow