How to stop EF (Code First) Checking circuit changes

I have a problem that causes hair loss ...

I have a project build using Code First (EF); everything is fine, and it works like a charm, however I can’t find a suitable way to allow changes to the database (via .sql scripts) without an application that throws hysteria at startup because the circuit has changed.

I read and read this problem, I deleted the EdmMetaData table so that it could not compare the database hash, but then read that there was an error in EF with this, if it is deleted, it still considers the scheme (since it does not recognize missing table, so it compares an empty row!).

In addition, I tried using Database.SetInitializer (null) in the Global.asax file, but that means I cannot access the data model later.

Everyone is talking about using the option to delete the database when changing the scheme, etc.

This is what I am looking for:

For EF / Code First do ... NOTHING! Sweet FA! Dumbass!

... If I change the circuit through an external application, I want it to completely ignore the changes and just ASSUME. I applied the appropriate model changes to work with these database changes made using the .sql script. If I skip a column or a table, I will accept my stupidity, and I expect tantrums, but until I make a mistake, I want EF to trust me.

This means that I can easily update any of our clients using the .sql script, at any time and not worry that EF will grow !: (

ANY ideas guys ??

+6
source share
2 answers

With newer versions of the Entity Framework, you no longer need to do what Ladislav Mrnka says. Starting with EF 4.3, you just need to set the initializer for the WebContext to null. For instance:

Database.SetInitializer<FabrikamFiberWebContext>(null); 
+7
source

In addition to setting the initializer to null also add this to your context class:

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

It will disable the hash comparison.

+5
source

Source: https://habr.com/ru/post/910775/


All Articles