carewithl
carewithl

Reputation: 1153

How does EF Code-First migration tool figure out which changes were made to the model?

I'm learning migrations and I'm curious how migration tool figures out which changes to our model were made after the last migration was created.

For example, assume we created a migration M1 and apply it by issuing command Update-Database. After applying M1, if we add a new property P to a class C and create another migration M2 by issuing command Add-Migration M2, then migration tool will somehow be able to figure out that only change ( after M1 was created ) we made to the model was adding a new property P to class C. How does migration tool figure that out?

thank you

REPLY:

Migrations uses __Migrations table to figure which migrations have already been applied and which have yet to be applied, but I thought it doesn't use this table to also figure out what changed from one migration to another, since data in migrations table is a hash, which means it can't be decrypted, which I assume would be necessary so that current model metadata can be compared with latest metadata stored in the migrations table?!

Or are you implying that it is able to figure out just by comparing hash values ( of current and stored versions ) which properties have changed or were deleted or were added to an entity?

Upvotes: 1

Views: 839

Answers (2)

Ivan Doroshenko
Ivan Doroshenko

Reputation: 942

The model is stored in .resx file under each mifration in the Target resource value. It is an encoded (serialized) model. It is used to compare your current model and generate the next migration.

Upvotes: 0

Pawel
Pawel

Reputation: 31610

It stores your model versions in the database (migrations history table) and compares your current model with the model stored in your database.

Upvotes: 1

Related Questions