After having some trouble with Entity Framework and SQL 2008 I decided to do a simple test so I created the following class. After testing it with a generated sdf I created a table with the same structure in a test database using sql 2008.
public class People {
[Key] int ID { get; set; }
string FirstName { get; set; }
string LastName { get; set; }
}
The problem is no matter what I do I get the following error.
The model backing the 'DataContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the RecreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
I must be doing something wrong or I'm missing a call somewhere.
Any thoughts?
Answer
In case the link ever disappears and anyone else wants to know what the answer was:
public class DataContext: DbContext {
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.IncludeMetadataInDatabase = false;
}
}
What's interesting about the link is that I also tried creating a model from the DB by using ADO.NET Entity Data Model
generator in VS and it resulted in the same types and also didn't work. But the above did. Good luck anyone else.