Just found out the answer and thought of updating here. Just need to do the following.

public class AddressBook: DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.IncludeMetadataInDatabase = false;
}
}

以下内容引用自:http://www.cnblogs.com/libingql/p/3351275.html

Entity Framework数据库初始化方式

Entity Framework通过Database.SetInitializer来指定需要的数据库初始化方式,Database.SetInitializer可指定的数据库共有3种:

  1>. CreateDatabaseIfNotExists

  CreateDatabaseIfNotExists是Database.SetInitializer指定数据库的默认方式,用于当数据库不存在时,自动创建数据库。由于该方式是默认方式,所以可以不需要任何代码进行指定,当然也可以使用代码来明确的指定。

Database.SetInitializer(new CreateDatabaseIfNotExists<PortalContext>());

  2>. DropCreateDatabaseWhenModelChanges

  DropCreateDatabaseWhenModelChanges用于当数据模型发生改变时,先删除原数据库,后创建新的数据库。

Database.SetInitializer(new DropCreateDatabaseIfModelChanges<PortalContext>());

  3>. DropCreateDatabaseAlways

  DropCreateDatabaseAlways用于每次均先删除原数据库再创建新的数据库,不管数据模型是否发生改变。

Database.SetInitializer(new DropCreateDatabaseAlways<PortalContext>());

  但是,在很多时候,我们希望即使在Entity Framework Code First与数据库不匹配时,宁可Entity Framework Code First报出数据库连接错误,而不希望对数据库进行任何的删除创建操作。Entity Framework Code First提供关闭数据库初始化操作:

Database.SetInitializer<PortalContext>(null);

The model backing the <Database> context has changed since the database was created.的更多相关文章

  1. EF框架CodeFirst the model backing the 'PModelEntities' context has changed since the database was created. Consider using Code First Migrations to update the database

    1.采用code first 做项目时,数据库已经生成,后期修改数据库表结构.再次运行时出现一下问题: Entity Framework : The model backing the 'Produc ...

  2. Model backing a DB Context has changed; Consider Code First Migrations

    Model增加一个字段,数据库对应的也手动添加了字段但是运行时报错 The model backing the 'TopLogDbContext' context has changed since ...

  3. The model backing the 'XXX' context has changed 错误

    https://blog.csdn.net/hit_why/article/details/72778785 https://blog.csdn.net/hit_why/article/details ...

  4. Entity Framework : The model backing the '' context has changed since the database was created

    1.采用code first 做项目时,数据库已经生成,后期修改数据库表结构.再次运行时出现一下问题: Entity Framework : The model backing the '' cont ...

  5. The model backing has changed

    其他信息: The model backing the 'WebTopFormContext' context has changed since the database was created. ...

  6. The entity type XXX is not part of the model for the current context.

    今天遇到了一个奇葩问题,虽然解决了,但还是一脸懵,先附赠一下别人的解决方案:https://www.cnblogs.com/zwjaaron/archive/2012/06/08/2541430.ht ...

  7. Sql server在使用sp_executesql @sql执行文本sql时,报错: Could not find database ID 16, name '16'. The database may be offline. Wait a few minutes and try again.

    最近在公司项目中使用exec sp_executesql @sql执行一段文本sql的时候老是报错: Could not find database ID 16, name '16'. The dat ...

  8. The backup set holds a backup of a database other than the existing ‘dbName’ database

     [Solved] System.Data.SqlClient.SqlError: The backup set holds a backup of a database other than t ...

  9. The entity type <type> is not part of the model for the current context

    这是在网站里遇到的一个错误,自动生成的不能手动添加, reference: http://stackoverflow.com/questions/19695545/the-entity-type-xx ...

随机推荐

  1. 20145301&20145321&20145335实验二

    20145301&20145321&20145335实验二 这次实验我的组员为:20145301赵嘉鑫.20145321曾子誉.20145335郝昊 实验内容详见:实验二

  2. Xamarin开发Android笔记:TextView行间距设定

    TextView 在使用TextView的时候会遇到调整行间距的问题,可通过Layout文件添加属性完成,具体属性如下: //设置行间距,如”3dp”. android:lineSpacingExtr ...

  3. 【Leetcode】【Medium】Decode Ways

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  4. TypeScript开发手册

    返回TS学习总目录 基本类型(Basic Types) 接口(Interfaces) 类(Classes) 模块(Modules) 函数(Functions) 泛型(Generics) 常见错误(Co ...

  5. 在Debian下编译Postgresql

    今天起床看到床头上的那本<PostgreSQL数据库内核分析>,发觉这书买了这么长时间,虽然大致看了一遍,可还没亲手实践.今天就花了点时间搭了个调试环境. 环境:Debian 7.0 ## ...

  6. [OpenCV] 2、边缘检测 canny

    >_<" 边缘检测代码:

  7. sql 取首次投资的人

    --- 11月 ---首次投资笔数和投资金额 ) AS stNum,sum(amount) AS stAmount FROM ( ),createtime,) AS riqi,a.amount,a.u ...

  8. js 函数提升和变量提升

    总结: 函数提升比变量提升优先级高! 词法分析 词法分析方法: js运行前有一个类似编译的过程即词法分析,词法分析主要有三个步骤: 分析参数 再分析变量的声明 分析函数说明 具体步骤如下: 函数在运行 ...

  9. paip.c3p0 nullpointexcept 配置文件根路径读取bug 解决

    paip.c3p0 nullpointexcept 配置文件根路径读取bug 解决 windows ok linux犯错误... 查看loging, 初始化的时候儿jdbcurl,user,pwd都是 ...

  10. 使用jquery修改css中带有!important的样式属性

    当CSS中含有!important的样式属性时,普通的修改方式是会出现失败的.如下: <div class="test">使用jquery修改css中带有!import ...