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
Very nice article that shows how do have two contexts, one per DbProvider, and to be able to also generate different migrations:
https://jasonwatmore.com/post/2020/01/03/aspnet-core-ef-core-migrations-for-multiple-databases-sqlite-and-sql-server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With