The model supporting the "EFDbContext" context has changed since the database was created

My sql database table and Entity platform database context and Model class are correct, but I realized that the error has changed in the context:

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

My table looks like this:

 CREATE TABLE [dbo].[Jamies] ( [JamesID] INT IDENTITY (1, 1) NOT NULL, [Name] NVARCHAR (255) NOT NULL, CONSTRAINT [PK_dbo.Jamies] PRIMARY KEY CLUSTERED ([JamesID] ASC) ); 

My EFDbContext class is as follows:

 class EFDbContext : DbContext { public DbSet<AppInformation> AppInformation { get; set; } //public DbSet<Revision> Revisions { get; set; } public DbSet<James> Jamies{ get; set; } } 

My James class is as follows:

 public class James { [Key] public int JamesID { get; set; } [Required] [MaxLength(255)] public string Name { get; set; } } 

The JamesRepository is as follows:

 public class EFJamesRepository : IJamesRepository { private EFDbContext context = new EFDbContext(); public IQueryable<James> Jamies { get { return context.Jamies; } } ... 

My controller method looks wrong:

 public class JamesController : Controller { private IJamesRepository repository; public int PageSize = 2; public JamesController(IJamesRepository repo) { repository = repo; } public ViewResult List(int page = 1) { JamiesListViewModel model = new JamiesListViewModel { Jamies = repository.Jamies .OrderBy(s => s.Name) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = repository.Jamies.Count() } }; return View(model); } 

Any ideas?

+6
source share
1 answer

Add

 Database.SetInitializer<EFDbContext>(null); 

In the Global.asax file, disable ef migration. You seem to have a migration for some reason.

+16
source

All Articles