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 管理資料庫 架構。

適用於