Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I mostly created ASP.NET WebForms applications but in a current new project I see the need to create a small website to maintain the data in some tables.
So I thought about a site with 3 radio buttons (Environments Test, Acceptance and Production) a listview with available tables in the database and a gridview with the possibilities to edit, add, update and delete data.

What I have tried:

My problem is that in controller I use a webapi or an EF model. But that hold destinated addresses. I want based on the choosen environment the correct connectionstring i used in the EF model or the correct WebAPI address.

How to do that?
Posted
Updated 29-Nov-17 22:07pm
Comments
F-ES Sitecore 30-Nov-17 6:00am    
The DbContext class your database context objects inherit from can accept the name of a connection string in the constructor and the auto-generated code will be hard-coding that. You can create your own partial database context class that allows you to pass the connection string name yourself and that will let you set it when you create the context. If you google "entity framework runtime database connection" you'll see examples of how to do this.

It's quite a brittle solution though as it means all your databases need to have the exact same schema.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900