Where is modelBuilder.IncludeMetadataInDatabase in EF CTP5?

…衆ロ難τιáo~ 提交于 2019-12-07 02:38:21

问题


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.


回答1:


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



回答2:


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



回答3:


In EF 4.1

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



回答4:


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



来源:https://stackoverflow.com/questions/4484592/where-is-modelbuilder-includemetadataindatabase-in-ef-ctp5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!