0
I’m messing with the Entity Framework and I was mapping to a Many to Many class.
What happens is I used a method I can use inside the DbContext
to rename a table, and it works smoothly.
But I was wondering how this method works being that I do not call it anywhere in my program? In case it would be the method OnModelCreating()
.
class EfContext : DbContext
{
public DbSet<Editora> EditorasDbSet { get; set; }
public DbSet<Cliente> ClientesDbSet { get; set; }
public DbSet<Estado> EstadosDbSet { get; set; }
public DbSet<Governador> GovernadorsDbSet { get; set; }
public DbSet<Departamento> DepartamentosDbSet { get; set; }
public DbSet<Funcionario> FuncionariosDbSet { get; set; }
public DbSet<Pedido> PedidosDbSet { get; set; }
public DbSet<Consumidor> ConsumidoresDbSet { get; set; }
public DbSet<Autor> AutorsDbSet { get; set; }
public DbSet<Livro> LivrosDbSet { get; set; }
public EfContext()
{
CustomDBInitializer initializer = new CustomDBInitializer();
Database.SetInitializer<EfContext>(initializer);
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Autor>().HasMany(autor => autor.Livros).WithMany(livro => livro.Autores).Map( x =>
{
x.ToTable("livros_e_autores");
x.MapLeftKey("autor_id");
x.MapRightKey("livro_id");
});
}
}
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero
I believe that you have more curiosity in the way in which this process is implemented and executed. You can check out the EF Core project that is open source directly on github or use some Decompiler dll tool to view the version code you are using. Here is the reference of the Jetbrains dotPeek which is a well-known tool to perform this procedure: https://www.jetbrains.com/decompiler/. LA.
– leandro.andrioli