Database Initialization Strategies in Code-First:

You already created a database after running your Code-First application the first time, but what about the second time onwards?? Will it create a new database every time you run the application? What about the production environment? How do you alter the database when you change your domain model? To handle these scenarios, you have to use one of the database initialization strategies.

There are four different database initialization strategies:

  1. CreateDatabaseIfNotExists: This is default initializer. As the name suggests, it will create the database if none exists as per the configuration. However, if you change the model class and then run the application with this initializer, then it will throw an exception.
  2. DropCreateDatabaseIfModelChanges: This initializer drops an existing database and creates a new database, if your model classes (entity classes) have been changed. So you don‘t have to worry about maintaining your database schema, when your model classes change.
  3. DropCreateDatabaseAlways: As the name suggests, this initializer drops an existing database every time you run the application, irrespective of whether your model classes have changed or not. This will be useful, when you want fresh database, every time you run the application, like while you are developing the application.
  4. Custom DB Initializer: You can also create your own custom initializer, if any of the above doesn‘t satisfy your requirements or you want to do some other process that initializes the database using the above initializer.

To use one of the above DB initialization strategies, you have to set the DB Initializer using Database class in Context class, as shown below:

时间: 2024-10-12 17:22:06

Database Initialization Strategies in Code-First:的相关文章

Entity Framework Code-First(17):Database Initialization Strategy

Database Initialization Strategies in Code-First: You already created a database after running your Code-First application the first time, but what about the second time onwards?? Will it create a new database every time you run the application? What

Database Initialization Parameters for Oracle E-Business Suite Release 12

In This Document Section 1: Common Database Initialization Parameters For All Releases Section 2: Release-Specific Database Initialization Parameters For Oracle 10g Release 2 Section 3: Release-Specific Database Initialization Parameters For Oracle 1

What is the Database Initialization Parameter That is Associated to an ORA-32004 Error ?

APPLIES TO: Oracle Database - Enterprise Edition - Version 9.2.0.1 to 11.2.0.3 [Release 9.2 to 11.2]Information in this document applies to any platform.***Checked for relevance on 24-Jan-2012*** GOAL How to know which parameter is obsolete and/or de

Entity Framework Code-First(20):Migration

Migration in Code-First: Entity framework Code-First had different database initialization strategies prior to EF 4.3 like CreateDatabaseIfNotExists, DropCreateDatabaseIfModelChanges, or DropCreateDatabaseAlways. However, there were some problems wit

Inheritance in Entity Framework: Table per Hierarchy

source Link Introduction This is the Entity Framework article series. In our previous two articles we learned various approaches to working with Entity Framework and various strategies to handle a database in a code first approach. You can read it he

转载:Character data is represented incorrectly when the code page of the client computer differs from the code page of the database in SQL Server 2005

https://support.microsoft.com/en-us/kb/904803 Character data is represented incorrectly when the code page of the client computer differs from the code page of the database in SQL Server 2005 Email Print SYMPTOMS Consider the following scenario: In

【译著】Code First :使用Entity. Framework编程(6)

小分享:我有几张阿里云优惠券,用券购买或者升级阿里云相应产品最多可以优惠五折!领券地址:https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=ohmepe03 Chapter6 Controlling Database Location,Creation Process, and Seed Data 第6章 控制数据库位置,创建过程和种子数据 In previous chapters you have

EBS initialization parameters - Healthcheck

APPLIES TO: Oracle EBS Applications Performance - Version 11.5.10.2 to 12.2 [Release 11.5.10 to 12.2] Oracle Shipping Execution - Version 11.5.10.2 to 11.5.10.2 [Release 11.5.10] Information in this document applies to any platform. EBS 11i and R12 P

Logging and Intercepting Database Operations (EF6 Onwards)

Logging and Intercepting Database Operations Starting with Entity Framework 6, anytime Entity Framework sends a command to the database this command can be intercepted by application code. This is most commonly used for logging SQL, but can also be u