Unit test error : The model backing the '' context has changed since the database was created

Posted by Sheonarayan under Error and Solution on 3/10/2015 | Points: 10 | Views : 12519 | Status : [Administrator] | Replies : 0

Problem

While running a unit test method that tests the Controller action method that access the database, we get following error.

The model backing the '' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

Solution



The solution of this problem is to add following line into the constructor of DbContext class

System.Data.Entity.Database.SetInitializer<Models.MyContext>(null);

So the typical DbContext code looks like below

        public MyContext():base("name=MyConnectionString")
{
System.Data.Entity.Database.SetInitializer<Models.MyContext>(null);
}


Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com



Responses

(No response found.)

Login to post response