none
Entity Framework Code First - Database creation strategies vs Code first migrations RRS feed

  • Question

  • Hello All,

    I am creating an application using Code first(first time) approach. I found we that the following options 

    • Create database if it does not exist
    • Create database always
    • Create database when model changes
    • Customize

    for database creation. I also see articles of enabling migrations if model changes.Can some one point me the right and best approach for initial database creation and further approach when model changes without data getting deleted.

    Tuesday, December 29, 2015 5:10 AM

Answers

All replies

  • Hi Mrityunjay,

    If it's a new project without any existing database. You could use Code First to a New Database, and the following is an article about ‘Code First to a New Database’ for your reference.

    https://msdn.microsoft.com/en-us/data/jj193542

    If you have an existing database. You could use ‘Code First to an Existing Database’.  And the following is an article about ‘Code First to an Existing Database’ for your reference.

    https://msdn.microsoft.com/en-us/data/jj200620

    Besides, these articles also provide different Migration method.

    Best regards,



    Tuesday, December 29, 2015 8:01 AM
    Moderator
  • I like Database first.

    I consider EF is data access layer . but not data storage design layer.


    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.

    Monday, January 4, 2016 12:20 PM