4
I need to point out in the web part what context the system will use.
My project is divided as follows:
After its completion I had to "replicate" it, but using another bank. The tables are equal does not change anything, but it is in another database because it is another system. I just need to change the connection string of the web.config. I find "VERY WRONG" to leave two projects IDENTICAL only with 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 don’t know how to make an "IF" for a certain option. I thought about adding another constructor to use the other string Connection, but I don’t know if it is the most appropriate way.
And I call context with this class:
namespace RepositorioEF
{
public class ClientesRepositorioEF : IRepositorio<Clientes>
{
private readonly Contexto contexto;
public ClientesRepositorioEF()
{
contexto = new Contexto();
}
}
}
see if I got it right: you created a project and want to use the same project structure for another project. That’s it?
– Renan
That.. Just change the database.
– Diego Zanardo