0

Hello every one

I am new in .net MVC3 I have made a connection string in Web.config file, the connection is successfully created. below is my connection code

<add name="StoreDB" connectionString="Data Source=AMIT-PC;Initial Catalog=Store;User ID=sa;Password=****;Integrated Security=False"
  providerName="System.Data.SqlClient" />

After that i created DBConfig.cs class file for database table connection below is my code

  public class Store : DbContext
  {
    public Store()
    {

    }
    public DbSet<RegisterModel> myapp { get; set; }    
    public DbSet<Application> ApplicationFormModels { get; set; }
  }

There are basically two model i have created. First is RegisterModel and Seconds is Application model. When I run this code the error occured

The model backing the context has changed since the database was created.

When I use only one DbSet<RegisterModel> than the table is successfully created and all the CURD operation are successfully done but error occured when i create more than one DbSet.

Below is the screenshots enter image description here

looking forward for your inputs

Thanks in Advance

Sharma Vikram
  • 2,440
  • 6
  • 23
  • 46
  • Have you look at this?: http://stackoverflow.com/questions/3600175/the-model-backing-the-database-context-has-changed-since-the-database-was-crea – Farhad Jabiyev Mar 21 '15 at 06:20

1 Answers1

0

Go to your

Global.asax-->Application_Start() and add Database.SetInitializer<YourDbContext>(null);

When you create your model the Code first from your EF maps it to your database. It creates hash of the schema which is stored in the EdmMetadata table which is created with database. Existing databases won’t have the EdmMetadata table and so won’t have the has and the implementation will throw if that table is missing.

Or alternatively you can also do the following

 protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder) 
 { 
   modelBuilder.IncludeMetadataInDatabase = false; 
 } 

in your dbcontext

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rohit
  • 10,056
  • 7
  • 50
  • 82