Hi.. I am developing in .Net Core 1.1 and need to get the URL in Startup.cs
public void ConfigureServices(IServiceCollection services) { string Need_Url_here = ???? //services.AddDbContext<SmartContext>(opt => opt.UseSqlServer(connectionstring)); services.AddDbContext<SmartContext>(Need_Url_here); // Add framework services. services.AddMvc(); }
And pass it to the DBContext.For choose which database to connect ...
public class SmartContext : DbContext { public SmartContext(DbContextOptions<SmartContext> opt) : base(opt) { } public DbSet<BusinessEntity> BusinessEntity { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder ) { string conection = config["Data:"+ Need_Url_here+ ":ConnectionString"]; // define the database to use optionsBuilder.UseSqlServer(conection); }
Can someone help me ?