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:
- 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.
- 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.
- 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.
- 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:
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 ...
- Database Initialization Parameters for Oracle E-Business Suite Release 12 (文档 ID 396009.1)
In This Document Section 1: Common Database Initialization Parameters For All Releases Section 2: Re ...
- Database Initialization Parameters for Oracle E-Business Suite Release 12
In This Document Section 1: Common Database Initialization Parameters For All Releases Section 2: Re ...
- Entity Framework Code-First(6):Database Initialization
Database Initialization: We have seen that Code First creates a database automatically in the Simple ...
- EntityFramework6.X 之 Database Initialization
Database Initialization 下图是数据库初始化的工作流 EF为数据库初始化准备了多种策略: l CreateDatabaseIfNotExists:这是默认的初始化策略 l D ...
- 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] ...
- java Class的Long id初始化 为0的问题android数据库操做出现的 android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
java的class中的Long类型变量调用默认的 构造函数new后会被初始化为0. 这句话大家可能感觉这么低级的事情还用你说? 我想说的是这个会产生的一个应用场景 和 避免方法 场景:db插入时候p ...
- Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default}) (state=08S01,code=0)
sparksql 2.和hive2.1.1 由于sparksql中的hive-cli 等包的版本是1.2的需要自己下载,下载替换之后不报错,替换之前做好备份
- Entity Framework Code-First(20):Migration
Migration in Code-First: Entity framework Code-First had different database initialization strategie ...
随机推荐
- ITEM M6 自增(INCREMENT)、自减(DECREMENT)操作符前缀形式与后缀形式的区别
前缀自增 UPInt & UPint::operator++() { *this+=1; return *this; } 后缀自增 const UPInt & UPint::opera ...
- 网络流 POJ2112
题意:K个产奶机,C头奶牛,每个产奶机最多可供M头奶牛使用:并告诉了产奶机.奶牛之间的两两距离Dij(0<=i,j<K+C). 问题:如何安排使得在任何一头奶牛都有自己产奶机的条件下,奶牛 ...
- Ext-进度条
1.progress使用 Ext.MessageBox.progress('请等待',msg:'读取数据中……'); 真实案例 tqbtnNews:function(){ var me = this; ...
- Java多线程学习(吐血超详细总结)
本文主要讲了java中多线程的使用方法.线程同步.线程数据传递.线程状态及相应的一些线程函数用法.概述等. 首先讲一下进程和线程的区别: 进程:每个进程都有独立的代码和数据空间(进程上下文),进程间的 ...
- 【USACO 2.1】Ordered Fractions
/* TASK: frac1 LANG: C++ URL: http://train.usaco.org/usacoprob2?S=frac1&a=dbgwn5v2WLr SOLVE: 直接枚 ...
- 【USACO 1.4】Arithmetic Progressions
/* TASK: ariprog LANG:C++ URL:http://train.usaco.org/usacoprob2?a=PA9lOcZrdWq&S=ariprog SOLVE:平方 ...
- Leetcode 113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- 【BZOJ-1068】压缩 区间DP
1068: [SCOI2007]压缩 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1001 Solved: 615[Submit][Status][ ...
- 【poj3122】 Pie
http://poj.org/problem?id=3122 (题目链接) 题意 给出N个pie的半径和F个friend,每个friend得到的pie必须一样,求每个人能得到的pie的最大大小. so ...
- bzoj2716: [Violet 3]天使玩偶
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...