Run different database types in different environments in dotnet core 2 Run different database types in different environments in dotnet core 2 sqlite sqlite

Run different database types in different environments in dotnet core 2


So I guess I found a nice way for you to do that. You can use the ConfigureDevelopmentServices startup convention to add your SQLSite DbContext. So, just as some basic example you would have:

// Production "like" ConfigureServicespublic void ConfigureServices(IServiceCollection services){    // Use Sql Server    services.AddDbContext<SchoolContext>(options =>        options.UseSqlServer(Configuration.GetConnectionString("ProductionConnection")));}// Development ConfigureServicespublic void ConfigureDevelopmentServices(IServiceCollection services){    // Use SQL Lite    services.AddDbContext<SchoolContext>(options =>        options.UseSqlite(Configuration.GetConnectionString("DevelopmentConnection")));}

You can even go further and add a ConfigureStagingServices if you happen to have another different context for staging only. To avoid copy and pasting of common services, you could have a private method that register the common services and have the separate ones only with specific stuff.

Now for the migrations, I never tested this but, my best guess is if you have the correct dbContext and the correct connection string, the migrations will work fine. You just point to the EF project and run it.