Doubt Entity Framework Core

Asked

Viewed 40 times

0

I’m learning to program using EF, I’m doing from BD First, I have a BD from another project, and I would like to create a solution based on this comic, I decided to leave very quietly, starting with a list of a certain X table, my question is: do I need to create my model classes with the same name as the tables in the database? in my bank there is an Establishment table and in the project an Establishment class that is the representation of this table, or no problem?

  • And why learn from something that is already obsolete?

  • and what technology would you indicate friend?

  • The question is a bit confusing, because you use EF Core, this should be used, but it does not have DB First, so you are not using it.

  • db first was the way I meant I’m doing the project using the structure of a ready-made comic as the basis of the business, in the same way I could do the project using code first, in this case I would be creating the comic based on my business classes(models)using the Migrations...

1 answer

1


You don’t need your class names to be equal to table names, but you need to map the class to the table.

Code example of OnModelCreating:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<Estabelecimento>(cfg => 
    {
        cfg.ToTable("Establishment"); //para identificar o nome da tabela
        cfg.Property(e => e.Nome).HasColumnName("Name"); // para identificar o nome da coluna
    });
}

  • I did some tests here and it worked, just yesterday when I asked the question, I tested to change the names of the classes with the same of the comic and the attributes in the same way, it worked equally... in this case using Onmodelcreating, I would have to map each class and its attributes according to the comic?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.