Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are the compressed models stored in the EF 4.3 Code First Migrations __MigrationHistory table created?

I'm working with Code First Migrations (Entity Framework 4.3) and I'd like to get a compressed binary version of the current model, so that I can manually compare it to the latest model stored in the __MigrationHistory table (or to one I have stored in a text file).

There is the EdmMetadata.TryGetModelHash() method, but that's marked as deprecated and I want to avoid it if possible (for future-proofing reasons).

How would I do this under EF 4.3?

Edit: From a bit more investigation and the info in Pawel's answer I've figured out that this field no longer stores a hash but a compressed binary representation of the model. It's this I'm trying to create.

like image 457
Mark Bell Avatar asked May 21 '12 10:05

Mark Bell


People also ask

What is migrations history table?

What is Migrations History Table? Migrations history table is a table used by Code First Migrations to store details about migrations applied to the database. By default the name of the table in the database is __MigrationHistory and it is created when applying the first migration to the database.

How do I create an EF migration?

Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.


1 Answers

__MigrationHistory table no longer contains a hash of the model. Instead it now contains the model in the compressed form. Also, verifying whether the model changed or not no longer relies on just comparing the hash since Migrations need to "know" what changed and how it did change.

EdmMetadata was a table that was being used before Migrations were integrated to Entity Framowork in 4.3/5.0 and won't be created in databases created by EF 4.3+. You can find some additional details here as well: http://blog.oneunicorn.com/2012/01/13/ef-4-3-beta-1-what-happened-to-that-edmmetadata-table/

like image 129
Pawel Avatar answered Oct 31 '22 16:10

Pawel