Skip to content

Instantly share code, notes, and snippets.

@baywet
Created March 2, 2016 22:54
Show Gist options
  • Save baywet/9931ba2f45043dba9bdb to your computer and use it in GitHub Desktop.
Save baywet/9931ba2f45043dba9bdb to your computer and use it in GitHub Desktop.
This file will allow you to pass a connection string as a parameter in powershell
using Microsoft.Data.Entity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace YourDbContextNameSpace
{
public class Startupupdate
{
public Startupupdate()
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var connection = Configuration["UpdateConnectionString"];
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<YourDbContext>(options => options.UseSqlServer(connection));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment