locked
General question on EF RRS feed

  • Question

  • User-2097295820 posted

    When you run the command enable-migrations.

    A Configuration file is created. So from my understanding AutomaticMigrationsEnabled = true; This should be done. To allow the database to be able perform update.

    But inside this Configuration file. There is a Seed () method. From my experience. When you Add migrations and update-database.

    Content of the Seed method would always run.

    In my application I have information of Country, Continent, States which I seed in the Configuration file.

    QUESTIONS

    1. When I run the command update-database. Does the seed () in the configuration file run always.

    2. If I make lot of major schema changes to my database and the database contains live data. If I run the update-database would there be issues. Take example of signficant schemma change like foriegn key and primary keys and the live db has data tied to this. How would EF solve this. ?

    3. DatabaseInitializer from what I know informations you want to be seeded on a first time should be kept here and remove during production ?

    4. When I connect to my Azure db from Vs2013. I keep getting the error database version issue. Do I need to update any thing in vs 2013. Or should I outwriting install Vs2015.

    5. In my project I used a lot of Stored procedures. I used the Seed () method of the Configuration file to create all my Stored procedures. I used context.Database.ExecuteSqlCommand() inside the Seed(). So while system is running live there would be cases were I need to update SP codes. Am I suppose update SP manually or is there a better way of handling SP codes. I am even thinking of putting the SP codes in a DatabaseInitializer file. which would be run only once since they are CREATE PROCEDURE. statements

    Please I am asking all this questions because I am lately trying to learn how to update database systems when live users are using your platform. My orm is EF. So I know I need to understand things to the fundamentals

    Monday, December 5, 2016 10:49 AM

Answers

  • User-821857111 posted

    1. When I run the command update-database. Does the seed () in the configuration file run always.
    Yes.

    2. If I make lot of major schema changes to my database and the database contains live data. If I run the update-database would there be issues. Take example of signficant schemma change like foriegn key and primary keys and the live db has data tied to this. How would EF solve this. ?
    It doesn't. You need to take steps to resolve this yourself.
    3. DatabaseInitializer from what I know informations you want to be seeded on a first time should be kept here and remove during production ?
    That's up to you. You can seed the database with anything you want. I have used the Seed method to populate a database with lookup data which I have kept in production.

    4. When I connect to my Azure db from Vs2013. I keep getting the error database version issue. Do I need to update any thing in vs 2013. Or should I outwriting install Vs2015.
    If you are connecting to a live database from an application that has changes that haven't been made to the live database, then you may get errors about model mismatches.

    I never use VS to connect to a database. I only ever use SQL Server Management Studio. I use the update-database -script option to generate migration scripts to execute against the database.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 5, 2016 1:29 PM
  • User-821857111 posted

    update-database -script

    I notice that this command basically just generate the script without running the script on the database.

    Yes - that's what it does.

    I started getting errors of some delete column issues.

    Please do you edit the script generated before running on your live db.

    I have never had to modify the generated SQL, no.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 9, 2016 1:57 PM

All replies

  • User-821857111 posted

    1. When I run the command update-database. Does the seed () in the configuration file run always.
    Yes.

    2. If I make lot of major schema changes to my database and the database contains live data. If I run the update-database would there be issues. Take example of signficant schemma change like foriegn key and primary keys and the live db has data tied to this. How would EF solve this. ?
    It doesn't. You need to take steps to resolve this yourself.
    3. DatabaseInitializer from what I know informations you want to be seeded on a first time should be kept here and remove during production ?
    That's up to you. You can seed the database with anything you want. I have used the Seed method to populate a database with lookup data which I have kept in production.

    4. When I connect to my Azure db from Vs2013. I keep getting the error database version issue. Do I need to update any thing in vs 2013. Or should I outwriting install Vs2015.
    If you are connecting to a live database from an application that has changes that haven't been made to the live database, then you may get errors about model mismatches.

    I never use VS to connect to a database. I only ever use SQL Server Management Studio. I use the update-database -script option to generate migration scripts to execute against the database.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 5, 2016 1:29 PM
  • User-2097295820 posted

    Thanks for your response mike

     update-database -script

    I notice that this command basically just generate the script without running the script on the database. I tried following your approach running the script that was generated on a different version of my db in SQL Management studio. But I started getting errors of some delete column issues.

    Please do you edit the script generated before running on your live db. If so advise me.

    Thanks alot am grateful for your response and time

    Friday, December 9, 2016 11:35 AM
  • User-821857111 posted

    update-database -script

    I notice that this command basically just generate the script without running the script on the database.

    Yes - that's what it does.

    I started getting errors of some delete column issues.

    Please do you edit the script generated before running on your live db.

    I have never had to modify the generated SQL, no.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 9, 2016 1:57 PM