DatabaseFacade.EnsureCreated 메서드

정의

컨텍스트에 대한 데이터베이스가 있는지 확인합니다.

public virtual bool EnsureCreated ();
[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 EnsureCreated ();
abstract member EnsureCreated : unit -> bool
override this.EnsureCreated : 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 EnsureCreated : unit -> bool
override this.EnsureCreated : unit -> bool
Public Overridable Function EnsureCreated () As Boolean

반환

true 데이터베이스가 만들어졌으면 이고, false 이미 있는 경우 입니다.

특성

설명

  • 데이터베이스가 있고 테이블이 있는 경우 아무 작업도 수행되지 않습니다. 데이터베이스 스키마가 Entity Framework 모델과 호환되는지 확인하기 위해 아무 작업도 수행되지 않습니다.
  • 데이터베이스가 있지만 테이블이 없는 경우 Entity Framework 모델을 사용하여 데이터베이스 스키마를 만듭니다.
  • 데이터베이스가 없으면 데이터베이스가 만들어지고 Entity Framework 모델이 데이터베이스 스키마를 만드는 데 사용됩니다.

Entity Framework를 사용하여 테스트하거나 프로토타입을 생성할 때 바로 다음 EnsureDeleted() 을 사용하는 EnsureCreated() 것이 일반적입니다. 이렇게 하면 각 테스트/프로토타입을 실행하기 전에 데이터베이스가 클린 상태에 있게 됩니다. 그러나 데이터베이스의 데이터는 보존되지 않습니다.

이 API는 **not**을(를) 사용하여 데이터베이스를 만듭니다. 또한 생성된 데이터베이스는 나중에 마이그레이션을 사용하여 업데이트할 수 없습니다. 관계형 데이터베이스를 대상으로 하고 마이그레이션을 사용하는 경우 를 사용하여 Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate 마이그레이션을 사용하여 데이터베이스가 생성되고 모든 마이그레이션이 적용되었는지 확인할 수 있습니다.

자세한 내용 과 예제는 EF Core데이터베이스 만들기 API 를 사용하여 데이터베이스 스키마 관리를 참조하세요.

적용 대상