/// <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 bool EnsureCreated()
        {
            var created = _cosmosClient.CreateDatabaseIfNotExists();

            foreach (var entityType in _model.GetEntityTypes())
            {
                created |= _cosmosClient.CreateContainerIfNotExists(
                    entityType.GetContainer(),
                    GetPartitionKeyStoreName(entityType));
            }

            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;
                    }
                }

                _database.SaveChanges(updateAdapter.GetEntriesToSave());
            }

            return(created);
        }
Ejemplo n.º 2
0
        public bool EnsureCreated()
        {
            var created = _cosmosClient.CreateDatabaseIfNotExists();

            foreach (var entityType in _stateManagerDependencies.Model.GetEntityTypes())
            {
                created |= _cosmosClient.CreateContainerIfNotExists(entityType.Cosmos().ContainerName, "__partitionKey");
            }

            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);
                    }
                }

                stateManager.SaveChanges(acceptAllChangesOnSuccess: false);
            }

            return(created);
        }
Ejemplo n.º 3
0
        /// <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 bool EnsureCreated()
        {
            var created = _cosmosClient.CreateDatabaseIfNotExists();

            foreach (var entityType in _model.GetEntityTypes())
            {
                var containerName = entityType.GetContainer();
                if (containerName != null)
                {
                    created |= _cosmosClient.CreateContainerIfNotExists(
                        containerName,
                        GetPartitionKeyStoreName(entityType));
                }
            }

            if (created)
            {
                Seed();
            }

            return(created);
        }