开发者

Where is modelBuilder.IncludeMetadataInDatabase in EF CTP5?

开发者 https://www.devze.com 2023-01-31 21:13 出处:网络
With CTP4, I used to be able to do the following (as suggested by ptrandem): modelBuilder.IncludeMetadataInDatabase = false

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 开发者_如何学JAVA 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.


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>();


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);


In EF 4.1

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
}


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 (...)

0

精彩评论

暂无评论...
验证码 换一张
取 消