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