I need the web part to point out which context the system will use.
My project is divided as follows:
AftercompletingitIhadto"replica it", but using another bank. The tables are the same does not change anything, but it is in another bank because it is another system. I just need to change the web.config connection string. I find it "VERY WRONG" to leave two IDENTICAL projects with only the different connection string.
namespace RepositorioEF
{
public class Contexto : DbContext
{
public DbSet<Cartas> Carta {get;set;}
public DbSet<Clientes> Clientes { get; set; }
public DbSet<Loja_Carrossel> Carrossel { get; set; }
public DbSet<Loja_Menus> Menu { get; set; }
public DbSet<Loja_Produtos> Produto { get; set; }
public DbSet<Loja_Submenus> Submenu { get; set; }
public DbSet<Pedidos> Pedido { get; set; }
public DbSet<Pedidos_Itens> PedidoItem { get; set; }
public DbSet<Pedidos_Status> PedidoStatus { get; set; }
public DbSet<Loja_Codigo> Codigo { get; set; }
public DbSet<Loja_Usuarios> Usuarios { get; set; }
public DbSet<Loja_ActionsLog> ActionsLog { get; set; }
public Contexto()
: base("BancoDados")
{
Database.SetInitializer<Contexto>(null);
}
}
}
This is the class of my context and I do not know how to make an "IF" for that option. I thought of adding another constructor to use the other connection string, but I do not know if it's the right way.
And I call the context with this class:
namespace RepositorioEF
{
public class ClientesRepositorioEF : IRepositorio<Clientes>
{
private readonly Contexto contexto;
public ClientesRepositorioEF()
{
contexto = new Contexto();
}
}
}