语言

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 管理数据库 架构。

适用于