DatabaseFacade.EnsureDeleted 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
確定內容的資料庫不存在。 如果不存在,則不會採取任何動作。 如果存在,則會刪除資料庫。
警告:刪除整個資料庫,而且不努力只移除模型用於此內容的資料庫物件。
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 管理資料庫 架構。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應