Using an existing database

Asked

Viewed 315 times

0

I have a database (SQL-Server); if I connect to it, I still have to create the classes EPH and use a Migration?

  • And why you can’t use database-first?

1 answer

1


Good afternoon, the usability of EF with Migrations goes from its implementation.

You can simply connect to the database and use it as it is. If you want to use Migrations you should do its implementation according to the documentations and tutorials spread over the internet, so when generating a database with Migration it will be based on the classes mapped with EF, and your bank already created will only undergo the divergent changes it made to the Migrations itself.

So say your bank has the Table Person with the fields Name and Age
The class in the code would be:

class Pessoa {
  public string Nome { get; set;}
  public int Idade { get; set;}
}

If you run a new Migration, a database will be created with this table as it is in the code (Code First). If you put an extra field in the code and run Migration it should update any existing database as well.

This was a theoretical explanation of Migration and its behavior, to implement it in this way consult other materials.

  • Yes, I just want to connect to the existing base, I want to use the ADO.Net Entity Data Model. to map my classes, but VC2017 no longer has this option?

  • I don’t work with ADO.NET, but according to the releases nothing related to ADO.NET was removed..

  • I found a link in the documentation teaching how to implement a basic application with ADO.NET, make sure it can help you. My branch extends to EF. Documentation link

  • @Cesaraugustus This was discontinued, it only brought problems

  • tah, is that I’m trying to follow an exercise that asks: 1º - Create an ASP.NET MVC project that connects to the previously created SQL Server database, using Entity Framework database first (EDMX) for mapping tables into classes. already contain everything up to the data

  • Dude, a piece of advice goes right to the EF, it’s more robust and complex, but you have more control of your application.

Show 1 more comment

Browser other questions tagged

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