I am using Entity Framework 6, SQL 2008 R2, VS 2013.
To solve this problem, use only the following procedure:
1) delete the existing db (existing database created using the EF model {code first})
2) Launch APP again.
Example request code example (in layout):
this code creates db if my model is changed and will look for the username in the user table.
<body> @{ // Delete && Create ... Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DBContext>()); var db = new DBContext(); var SearchingUser = db.Users.Where(c => c.UserName == "qwertyui"); if (SearchingUser.Count() == 0) { var User = new Users { UserName = "qwertyui",Password = "12345678" }; db.Users.Add(User); db.SaveChanges(); } } @RenderSection("scripts", required: false) @RenderBody() </body>
source share