Database.CompatibleWithModel Method (Boolean)

Entity Framework 6.0

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

Namespace:   System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

public bool CompatibleWithModel(
	bool throwIfNoMetadata


Type: System.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.

Return Value

Type: System.Boolean

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

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.

Return to top