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 ...
随机推荐
- 网络流 最大流HDU 3549
//////////在这幅图中我们首先要增广1->2->4->6,这时可以获得一个容量为2的流,但是如果不建立4->2反向弧的话,则无法进一步增广,最终答案为2,显然是不对的, ...
- 【CodeForces 261B】Maxim and Restaurant(DP,期望)
题目链接 第一种解法是$O(n^3*p)$的:f[i][j][k]表示前i个人进j个人长度为k有几种方案(排列固定为123..n时).$f[i][j][k]=f[i-1][j][k]+f[i-1][j ...
- 如何更改IP地址的映射名字
windows系统下: 在C:\Windows\System32\drivers\etc\hosts里面添加你想对应的域名 如192.168.230.134 weekend110 注意:这要有管理员权 ...
- svn服务器无法访问时检查几个文件:
出现该问题基本都是三个配置文件的问题,下面把这个文件列出来. svnserve.conf:[general]anon-access = readauth-access = writepassword- ...
- C++强制类型转换操作符 static_cast
static_cast是一个强制类型转换操作符.强制类型转换,也称为显式转换,C++中强制类型转换操作符有static_cast.dynamic_cast.const_cast.reinterpert ...
- python调用模块&函数
一般模块是抽象的概念,按照功能划分模块,尽可能保证每个模块互相独立. 一般模块里有多个函数.当然,如果你愿意,也可以把一个几个模块写进一个大函数.对于python 模块,每个模块可以包含多个函数,但一 ...
- 使用触发器实现记录oracle用户登录失败信息到alert.log日志文件
前面我们说了用oracle自带的审计功能可以实现记录用户登录失败日志到数据表中(链接:http://www.54ok.cn/6778.html).今天我们来分享一下如何把用户登录失败信息记录到aler ...
- js-JavaScript高级程序设计学习笔记11
依然第十四章 1.选择部分文本:使用setSelectionRange()方法,两个参数为第一个字符的索引和最后一个字符之后的索引,类似于substring()方法. 2.IE8及更早版本使用范围选择 ...
- 【BZOJ-3784】树上的路径 点分治 + ST + 堆
3784: 树上的路径 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 462 Solved: 153[Submit][Status][Discuss ...
- Maven配置不成功
配置了MAVEN_HOME,新建了java文件,在d:/java/MAVEN_HOME/apach....,path下输出%MAVEN_HOME%bin,为什么cmd下mvn不行呢?因为MAVEN_H ...