Language

DatabaseFacade.EnsureDeleted メソッド

定義

コンテキストのデータベースが存在しないことを確認します。 存在しない場合、アクションは実行されません。 存在する場合は、データベースが削除されます。

警告: データベース全体が削除され、このコンテキストでモデルによって使用されるデータベース オブジェクトだけを削除する作業は行われません。

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

戻り値

true データベースが削除された場合は false 。存在しない場合は。

属性

注釈

Entity Framework を使用してテストまたはプロトタイプを作成するときは、EnsureDeleted()の直後にEnsureCreated()を使用するのが一般的です。 これにより、テスト/プロトタイプの各実行前にデータベースがクリーンな状態になります。 ただし、データベース内のデータは保持されないことに注意してください。

詳細と例については、「EF Core およびデータベース作成 API を使用したデータベース スキーマの管理」を参照してください。

適用対象