コード例 #1
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())
            {
                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);
        }
コード例 #2
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(
            IUpdateAdapterFactory updateAdapterFactory,
            IDiagnosticsLogger <DbLoggerCategory.Update> updateLogger)
        {
            lock (_lock)
            {
                var valuesSeeded = _tables == null;
                if (valuesSeeded)
                {
                    // ReSharper disable once AssignmentIsFullyDiscarded
                    _tables = CreateTables();

                    var updateAdapter = updateAdapterFactory.CreateStandalone();
                    var entries       = new List <IUpdateEntry>();
                    foreach (var entityType in updateAdapter.Model.GetEntityTypes())
                    {
                        foreach (var targetSeed in entityType.GetSeedData())
                        {
                            var entry = updateAdapter.CreateEntry(targetSeed, entityType);
                            entry.EntityState = EntityState.Added;
                            entries.Add(entry);
                        }
                    }

                    ExecuteTransaction(entries, updateLogger);
                }

                return(valuesSeeded);
            }
        }
コード例 #3
0
        private IUpdateAdapter AddSeedData()
        {
            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;
                }
            }

            return(updateAdapter);
        }
コード例 #4
0
        public virtual bool EnsureCreated(
            IUpdateAdapterFactory updateAdapterFactory,
            IDiagnosticsLogger <DbLoggerCategory.Update> updateLogger)
        {
            lock (_lock)
            {
                var valuesSeeded = _tables == null;
                if (valuesSeeded)
                {
                    // ReSharper disable once AssignmentIsFullyDiscarded
                    _tables = CreateTables();

                    var updateAdapter = updateAdapterFactory.CreateStandalone();
                    var entries       = new List <IUpdateEntry>();
                    foreach (var entityType in updateAdapter.Model.GetEntityTypes())
                    {
                        var key = _useNameMatching ? (object)entityType.Name : entityType;
                        //Load Data
                        var table = EnsureTable(key, entityType);

                        foreach (var targetSeed in entityType.GetSeedData())
                        {
                            var entry = updateAdapter.CreateEntry(targetSeed, entityType);
                            entry.EntityState = EntityState.Added;

                            ////update
                            if (table.Exists(entry))
                            {
                                entry.EntityState = EntityState.Modified;
                                foreach (var property in entry.EntityType.GetProperties().ToList())
                                {
                                    if (!property.IsKey())
                                    {
                                        entry.SetPropertyModified(property);
                                    }
                                }
                            }

                            entries.Add(entry);
                        }
                    }

                    ExecuteTransaction(entries, updateLogger);
                }

                return(valuesSeeded);
            }
        }
コード例 #5
0
        private IUpdateAdapter AddSeedData()
        {
            var updateAdapter = _updateAdapterFactory.CreateStandalone();

            foreach (var entityType in _designModel.GetEntityTypes())
            {
                IEntityType?targetEntityType = null;
                foreach (var targetSeed in entityType.GetSeedData())
                {
                    targetEntityType ??= updateAdapter.Model.FindEntityType(entityType.Name) !;
                    var entry = updateAdapter.CreateEntry(targetSeed, entityType);
                    entry.EntityState = EntityState.Added;
                }
            }

            return(updateAdapter);
        }