/// <summary> /// Deletes the database on the database server if it exists, otherwise does nothing. /// Calling this method from outside of an initializer will mark the database as having /// not been initialized. This means that if an attempt is made to use the database again /// after it has been deleted, then any initializer set will run again and, usually, will /// try to create the database again automatically. /// </summary> /// <returns> True if the database did exist and was deleted; false otherwise. </returns> public bool Delete() { using (var clonedObjectContext = _internalContext.CreateObjectContextForDdlOps()) { var deleted = _internalContext.DatabaseOperations.DeleteIfExists(clonedObjectContext.ObjectContext); if (deleted) { _internalContext.MarkDatabaseNotInitialized(); } return(deleted); } }
/// <summary> /// Deletes the database on the database server if it exists, otherwise does nothing. /// Calling this method from outside of an initializer will mark the database as having /// not been initialized. This means that if an attempt is made to use the database again /// after it has been deleted, then any initializer set will run again and, usually, will /// try to create the database again automatically. /// </summary> /// <returns> True if the database did exist and was deleted; false otherwise. </returns> public bool Delete() { if (!_internalContext.DatabaseOperations.Exists( _internalContext.Connection, _internalContext.CommandTimeout, new Lazy <StoreItemCollection>(CreateStoreItemCollection))) { return(false); } using (var clonedObjectContext = _internalContext.CreateObjectContextForDdlOps()) { _internalContext.DatabaseOperations.Delete(clonedObjectContext.ObjectContext); _internalContext.MarkDatabaseNotInitialized(); } return(true); }