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. html+css知识整理

    1.学网页最好的方法:学习别人的网页. 2.文档结构 <html>(超文本标记语言) <head>  <title>     </title>    & ...

  2. RecyclerView+CardView简单使用

    RecyclerView取代Listview用来显示数据,除此之外还能实现瀑布流的布局.CardView让我们的界面更好看,此外还将使用官方的下拉刷新. 添加支持: compile 'com.andr ...

  3. Kali Linux Web 渗透测试视频教程— 第十三课-密码破解

    Kali Linux Web 渗透测试— 第十三课-密码破解 文/玄魂 目录 Kali Linux Web 渗透测试— 第十三课-密码破解............................... ...

  4. NBIbatis 框架体系说明

    框架体系说明 Application 表现层 表现层必须通过Business业务规则层操作数据库,不能直接调用DataAccess数据访问. Sqlmap.config配置: connectionSt ...

  5. android 用NineOldAndroid实现的弹出按钮

    NineOldAndroid 1.首先上效果图: 左边这张是没有点击button的时候的效果,   右边这张是点击button 后是以该button为圆的展开5个button

  6. [MFC] 从文件读取与向文件添加数据

    CString str,str2,str3;str2="dsf",str3="dsfds"; CStdioFile myFile, File; if(myFil ...

  7. [51单片机] SPI nRF24L01 无线简单程序 1

    main.c #include <reg51.h> #include <api.h> #define uchar unsigned char /**************** ...

  8. 辐射4 中文武器命名方法, 不用winhex, 直接游戏内操作

    参考资料:https://www.reddit.com/r/fo4/comments/3t354b/tip_you_can_add_text_formatting_italic_underline/h ...

  9. thrift之TTransport层的缓存传输类TBufferedTransport和缓冲基类TBufferBase

    本节主要介绍缓冲相关的传输类,缓存的作用就是为了提高读写的效率.Thrift在实现缓存传输的时候首先建立一个缓存的基类,然后需要实现缓存功能的类都可以直接从这个基类继承.下面就详细分析这个基类以及一个 ...

  10. Atitit.dwr3 不能显示错误详细信息的解决方案,控件显示错误详细信息的解决方案 java .net php

    Atitit.dwr3 不能显示错误详细信息的解决方案,控件显示错误详细信息的解决方案 java .net php 1. Keyword/subtitle 1 2. 使用dwr3的异常convert处 ...