c# - How to correctly create a database using entity framework code first approach -


After creating the first database with the first structural code to prepare a database, I still can not believe that the right way What is the only way to create a database is using migration, so after installing those models I need, I use Package Manager and do it:

  Enable-Migration  

and then:

  Add-Migrate Initially:  
  update-database  

I have seen many tutorials like this one:

Talks about installing that model and after running the database, the database appears without any use of the migration, I am quite confused, therefore My questions are:

  1. Has the database been used after the statement? So in the above tutorial: using

      (var db = new bloggingcontext ())  
  2. Migration is generally used Is the database used to update only?

  3. What's the best way to get your opinion?

1 What database was used after the statement is? So in the above tutorial:

 using  (var db = new bloggingcontext ())  

It almost works, but you Additional syntax will be added, due to which EF executes some database, for example. Using

  (var db = new bloggingcontext ()) {db.YourDbSetProperty.Any (); }  

2. Is migration generally used to update the database?

Yes, with EF migration, you will be able to exclude the database and implement the changes made to the database without database. / P>

but it can also be used to generate database upgrade scripts.

3 What is the best way in your opinion?

This is mainly opinion, you can do anyway, but for the purpose of development on a local machine, I usually drop and recreate the code from the database, Migration is not using syntax.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -