Click here to Skip to main content
15,919,121 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i created a database as Accountuser , while the table as LogOn on the App directory folder.

on my browser, when i try to register a email and password , i always get this exception. i need your help to resolve this




The model backing the 'GuestBookContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:
C#
Line 36:                 if (ModelState.IsValid)
Line 37:                 {
Line 38:                     var CreUserFind = _db.accountdetails.Find(details.NEmail);
Line 39:                     if (CreUserFind != null)
Line 40:                     {

Source File: c:\Users\D doll\Documents\Visual Studio 2012\Projects\GuestBook\GuestBook\Controllers\AccountUserController.cs Line: 38

What I have tried:

C#
using GuestBook.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace GuestBook.Controllers
{
    public class AccountUserController : Controller
    {
        //
        // GET: /AccountUser/

        GuestBookContext _db = new GuestBookContext();

        protected override void Dispose(bool disposing)
        {
            _db.Dispose();
            base.Dispose(disposing);
        }

        [HttpGet]
        public ActionResult Registration()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Registration(LogOn details)
        {
            ViewBag.validResult = "Null";
            

                if (ModelState.IsValid)
                {
                    var CreUserFind = _db.accountdetails.Find(details.NEmail);
                    if (CreUserFind != null)
                    {
                        ViewBag.validResult = "Email Taken";
                        ModelState.AddModelError(" ", "The email is already taken");
                    }
                    else
                    {
                        var CreUser = _db.accountdetails.Create();
                        var simplecryp = new SimpleCrypto.PBKDF2();
                        var encrypto = simplecryp.Compute(details.NPassword);

                        CreUser.NEmail = details.NEmail;
                        CreUser.NPassword = encrypto;
                        CreUser.NPasswordSalt = simplecryp.Salt;
                        CreUser.UserId = Convert.ToString(Guid.NewGuid());
                        _db.accountdetails.Add(CreUser);
                        _db.SaveChanges();
                        ViewBag.validResult = "success";
                        ModelState.Clear();
                        ModelState.AddModelError("", "Regitration successfull");
                    
                }
          
            }
            return View();


for the model class
C#
namespace GuestBook.Models
{

    public class LogOn
    {
        public string UserId { get; set; }


        [Key]
        [Required(ErrorMessage = "*Enter  password")]
        [Display(Name = "Password")]
        public string NPassword { get; set; }

        [Required(ErrorMessage="*Enter email address")]
        [Display(Name = "Email Address")]
        public string NEmail { get; set; }

        public string NPasswordSalt { get; set; }
    }
}


for the model db context
C#
namespace GuestBook.Models
{
    public class GuestBookContext:DbContext
    {
        public GuestBookContext() : base("GuestBook") { }
        public DbSet<guestbookentry> details { get; set; }
        public DbSet<logon> accountdetails { get; set; }
    }
}
Posted
Updated 14-May-16 22:37pm
v2
Comments
Sergey Alexandrovich Kryukov 14-May-16 20:10pm    
This is good that you provided the line where the exception was thrown and "What I have tried" information, thank you.
Now, you also need to provide comprehensive exception information. Pay special attention for InnerException. Exception stack may also be useful.
—SA

1 solution

Are you looking for an explanation to the error message?
It says that your model do not mach anymore the underlying database and you have to update it (the database)...
Probably you added some fields to the model but did not reflected those fields in the database...
The error also suggest a tool to use from inside VS to do the update...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900