“自数据库创建以来,支持”上下文“的模型已经发生了变化 - 在不同的项目中 [英] 'The model backing the '' context has changed since the database was created' - in different project

查看:201
本文介绍了“自数据库创建以来,支持”上下文“的模型已经发生了变化 - 在不同的项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用EF与Code First Approach,我有一个用于认证的静态方法。如果我将其称为项目内容,则可以正常工作,但是如果我从不同的项目中调用它,则会收到以下错误:



支持上下文的模型自数据库创建以来已更改。考虑使用代码优先迁移来更新数据库...



有什么可能发生的想法?

解决方案

解决方案是:


  1. 将Entity Framework添加到每个项目

  2. 在您提出数据库的项目中添加Global.asax

  3. 在Application_Start中添加以下内容行:



    Database.SetInitializer< namespace.Entities>(null);


其中 Namespace.Entities 是您的 DbContext 的地址。


I'm using EF with Code First Approach and I have a static method that is used for authentication. If I call it inside the project, it works fine, if I however call it from a different project I get the following error:

The model backing the '' context has changed since the database was created. Consider using Code First Migrations to update the database...

Any ideas why that might be happening?

解决方案

The solution is:

  1. Add Entity Framework to each project
  2. Inside the project where you raise the database add Global.asax
  3. Inside the Application_Start add the following line:

    Database.SetInitializer< Namespace.Entities>(null);

where Namespace.Entities is the address to your DbContext.

这篇关于“自数据库创建以来,支持”上下文“的模型已经发生了变化 - 在不同的项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆