Created
March 2, 2016 22:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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