/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual async Task <bool> EnsureCreatedAsync(CancellationToken cancellationToken = default) { var created = await _cosmosClient.CreateDatabaseIfNotExistsAsync(cancellationToken); foreach (var entityType in _model.GetEntityTypes()) { created |= await _cosmosClient.CreateContainerIfNotExistsAsync( entityType.GetContainer(), GetPartitionKeyStoreName(entityType), cancellationToken); } if (created) { var updateAdapter = _updateAdapterFactory.CreateStandalone(); foreach (var entityType in _model.GetEntityTypes()) { foreach (var targetSeed in entityType.GetSeedData()) { var entry = updateAdapter.CreateEntry(targetSeed, entityType); entry.EntityState = EntityState.Added; } } await _database.SaveChangesAsync(updateAdapter.GetEntriesToSave(), cancellationToken); } return(created); }
public async Task <bool> EnsureCreatedAsync(CancellationToken cancellationToken = default) { var created = await _cosmosClient.CreateDatabaseIfNotExistsAsync(cancellationToken); foreach (var entityType in _stateManagerDependencies.Model.GetEntityTypes()) { created |= await _cosmosClient.CreateContainerIfNotExistsAsync(entityType.Cosmos().ContainerName, "__partitionKey", cancellationToken); } if (created) { var stateManager = new StateManager(_stateManagerDependencies); foreach (var entityType in _stateManagerDependencies.Model.GetEntityTypes()) { foreach (var targetSeed in entityType.GetData()) { var entry = stateManager.CreateEntry(targetSeed, entityType); entry.SetEntityState(EntityState.Added); } } await stateManager.SaveChangesAsync(acceptAllChangesOnSuccess : false); } return(created); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual async Task <bool> EnsureCreatedAsync(CancellationToken cancellationToken = default) { var created = await _cosmosClient.CreateDatabaseIfNotExistsAsync(cancellationToken) .ConfigureAwait(false); foreach (var entityType in _model.GetEntityTypes()) { var containerName = entityType.GetContainer(); if (containerName != null) { created |= await _cosmosClient.CreateContainerIfNotExistsAsync( containerName, GetPartitionKeyStoreName(entityType), cancellationToken) .ConfigureAwait(false); } } if (created) { await SeedAsync(cancellationToken).ConfigureAwait(false); } return(created); }