語言

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」。

適用於