ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview,SQL Server,Ajax,jQuery Plugins,jQuery UI,SSRS,XML,HTML,jQuery demos,code snippet examples.

Breaking News

  1. Home
  2. sql
  3. Context Has Changed Since the Database Was Created

Context Has Changed Since the Database Was Created

At present Entity Framework is used widely. We face some problems during working with Entity Framework. It takes lot of times to find out the perfect solutions. This article describes and provides the solutions of a common error in Entity Framework: Context has changed since the database was createdModel backing a DB Context has changedModel backing the context has changed since the database was created.
When we work with Microsoft Entity Framework sometimes we get the bellow error:
The model backing the ‘MyDBContext’ context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
This is the most frequent error in Entity Framework ASP.NET MVC. This type of error occurred when the model and the database cannot be mapped correctly. That means there is a modification or changed in the database. We made any type of schema change on the table or database after including Entity Data Modelin the project or solutions.
To resolve this problem there is lot of solution in the web. But most of them work with previous version of Entity Framework.
To solve this error writhe the following code in Application_Start() Method in Global.asax.cs file
Database.SetInitializer<CustomerDBContext>(null);
That means we need to bind our DB context class with a null value.
If the database schema is changed, it is mandatory to updates the .edmx file.

No comments