DatabaseFacade.EnsureDeleted Method

Definition

Ensures that the database for the context does not exist. If it does not exist, no action is taken. If it does exist then the database is deleted.

Warning: The entire database is deleted, and no effort is made to remove just the database objects that are used by the model for this context.

public virtual bool EnsureDeleted ();
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Migrations operations require building the design-time model which is not supported with NativeAOT Use a migration bundle or an alternate way of executing migration operations.")]
public virtual bool EnsureDeleted ();
abstract member EnsureDeleted : unit -> bool
override this.EnsureDeleted : unit -> bool
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Migrations operations require building the design-time model which is not supported with NativeAOT Use a migration bundle or an alternate way of executing migration operations.")>]
abstract member EnsureDeleted : unit -> bool
override this.EnsureDeleted : unit -> bool
Public Overridable Function EnsureDeleted () As Boolean

Returns

true if the database is deleted, false if it did not exist.

Attributes

Remarks

It is common to use EnsureCreated() immediately following EnsureDeleted() when testing or prototyping using Entity Framework. This ensures that the database is in a clean state before each execution of the test/prototype. Note, however, that data in the database is not preserved.

See Managing database schemas with EF Core and Database creation APIs for more information and examples.

Applies to