Share via


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 进行测试或制作原型时,通常立即使用 EnsureCreated() 以下 EnsureDeleted() 代码。 这可确保数据库在每次执行测试/原型之前处于干净状态。 但请注意,数据库中的数据不会保留。

有关详细信息和示例 ,请参阅使用 EF Core数据库创建 API 管理数据库 架构。

适用于