6

With CTP4, I used to be able to do the following (as suggested by ptrandem):

modelBuilder.IncludeMetadataInDatabase = false

With this line of code, EF doesn't create the EdmMetadata table in my database, and doesn't track model changes.

I was unable to find a way to accomplish this in the new CTP5, so now every time I change my model, I get this:

The model backing the 'MyContext' 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 DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

So, does everybody know where is the IncludeMetadataInDatabase property in CTP5? Thanks.

Community
  • 1
  • 1
Daniel Liuzzi
  • 16,807
  • 8
  • 52
  • 57

4 Answers4

10

CTP5 includes a very cool feature called Pluggable Conventions that can be used to Add/Remove conventions. IncludeMetadataInDatabase has been removed and being replaced with a
pluggable convention that does the same thing for you:

modelBuilder.Conventions
            .Remove<System.Data.Entity.Database.IncludeMetadataConvention>();
Morteza Manavi
  • 33,026
  • 6
  • 100
  • 83
  • Thanks, Morteza. Do you know if there are any other differences between doing this, and just dropping the EdmMetadata table as the ADO.NET team blog states? What is preferable? – Daniel Liuzzi Dec 19 '10 at 23:40
  • 2
    No problem. I think the one you found on team's blog is talking about existing databases and the one I suggested is for when you are generating a DB from your object model. At the end of the day they both have a same result: you have a POCO object model that works with a database without a Metadata table so I think it depends on your scenario (a brand new database or an existing one). – Morteza Manavi Dec 19 '10 at 23:53
  • 3
    In latest release, this got moved to modelBuilder.Conventions.Remove(); – bkaid Apr 24 '11 at 06:35
3

The equivalent in CTP5 to switch off initializer logic: In your Application_Start in Global.asax, enter the following:

System.Data.Entity.Database.DbDatabase.SetInitializer<MyDBContext>(null);
LordHits
  • 5,054
  • 3
  • 38
  • 51
3

In EF 4.1

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
}
Xorsat
  • 2,388
  • 21
  • 21
1

Have been looking for this all over, and I had to find the answer right after posting my question, DUH. Right from the ADO.NET team blog:

In CTP5 we have removed the need to perform additional configuration when mapping to an existing database. If Code First detects that it is pointing to an existing database schema that it did not create then it will ‘trust you’ and attempt to use code first with the schema. The easiest way to point Code First to an existing database is to add a App/Web.config connection string with the same name as your derived DbContext (...)

Daniel Liuzzi
  • 16,807
  • 8
  • 52
  • 57