Database.CompatibleWithModel(Boolean) Method

Definition

Checks whether or not the database is compatible with the the current Code First model.

public bool CompatibleWithModel (bool throwIfNoMetadata);
member this.CompatibleWithModel : bool -> bool
Public Function CompatibleWithModel (throwIfNoMetadata As Boolean) As Boolean

Parameters

throwIfNoMetadata
Boolean

If set to true then an exception will be thrown if no model metadata is found in the database. If set to false then this method will return true if metadata is not found.

Returns

True if the model hash in the context and the database match; false otherwise.

Remarks

Model compatibility currently uses the following rules. If the context was created using either the Model First or Database First approach then the model is assumed to be compatible with the database and this method returns true. For Code First the model is considered compatible if the model is stored in the database in the Migrations history table and that model has no differences from the current model as determined by Migrations model differ. If the model is not stored in the database but an EF 4.1/4.2 model hash is found instead, then this is used to check for compatibility.

Applies to