internal static string CreateObjectScript(AssociationSet associationSet)
        {
            JetCreateDatabaseSqlGenerator builder = new JetCreateDatabaseSqlGenerator();

            builder.AppendCreateForeignKeys(associationSet);
            return(builder.GetCommandText());
        }
        internal static string CreateObjectScript(EntitySet entitySet)
        {
            JetCreateDatabaseSqlGenerator builder = new JetCreateDatabaseSqlGenerator();

            builder.AppendCreateTable(entitySet);
            return(builder.GetCommandText());
        }
        /// <summary>
        /// Creates a database indicated by connection and creates schema objects (tables, primary keys, foreign keys) based on the contents of a StoreItemCollection.
        /// Note: in EF 6.1 this is not called if the provider implements Migration classes
        /// Note: we can't create database for Jet Connections
        /// </summary>
        /// <param name="connection">Connection to a non-existent database that needs to be created and populated with the store objects indicated with the storeItemCollection parameter.</param>
        /// <param name="commandTimeout">Execution timeout for any commands needed to create the database.</param>
        /// <param name="storeItemCollection">The collection of all store items based on which the script should be created.</param>
        /// <exception cref="System.ArgumentNullException">
        /// connection must not be null
        /// or
        /// storeItemCollection must not be null
        /// </exception>
        /// <exception cref="System.ArgumentException">The connection is not of type 'JetConnection'.</exception>
        protected override void DbCreateDatabase(DbConnection connection, int?commandTimeout, StoreItemCollection storeItemCollection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection must not be null");
            }

            if (storeItemCollection == null)
            {
                throw new ArgumentNullException("storeItemCollection must not be null");
            }

            JetConnection jetConnection = connection as JetConnection;

            if (jetConnection == null)
            {
                throw new ArgumentException("The connection is not of type 'JetConnection'.");
            }



            ConnectionState oldConnectionState = connection.State;

            if (oldConnectionState == ConnectionState.Closed)
            {
                connection.Open();
            }

            foreach (EntityContainer container in storeItemCollection.GetItems <EntityContainer>())
            {
                var entitySets = container.BaseEntitySets.OfType <EntitySet>().OrderBy(s => s.Name);

                foreach (EntitySet entitySet in container.BaseEntitySets.OfType <EntitySet>().OrderBy(s => s.Name))
                {
                    string createObjectScript = JetCreateDatabaseSqlGenerator.CreateObjectScript(entitySet);
                    jetConnection.CreateCommand(createObjectScript, commandTimeout).ExecuteNonQuery();
                }

                foreach (AssociationSet associationSet in container.BaseEntitySets.OfType <AssociationSet>().OrderBy(s => s.Name))
                {
                    string createObjectScript = JetCreateDatabaseSqlGenerator.CreateObjectScript(associationSet);
                    jetConnection.CreateCommand(createObjectScript, commandTimeout).ExecuteNonQuery();
                }
            }

            if (oldConnectionState == ConnectionState.Closed)
            {
                connection.Close();
            }
        }
        protected override string DbCreateDatabaseScript(string providerManifestToken, StoreItemCollection storeItemCollection)
        {
            if (providerManifestToken == null)
            {
                throw new ArgumentNullException("providerManifestToken must not be null");
            }

            if (storeItemCollection == null)
            {
                throw new ArgumentNullException("storeItemCollection must not be null");
            }

            return(JetCreateDatabaseSqlGenerator.CreateObjectsScript(storeItemCollection));
        }
        internal static string CreateObjectsScript(StoreItemCollection itemCollection)
        {
            JetCreateDatabaseSqlGenerator builder = new JetCreateDatabaseSqlGenerator();

            foreach (EntityContainer container in itemCollection.GetItems <EntityContainer>())
            {
                var entitySets = container.BaseEntitySets.OfType <EntitySet>().OrderBy(s => s.Name);

                foreach (EntitySet entitySet in container.BaseEntitySets.OfType <EntitySet>().OrderBy(s => s.Name))
                {
                    builder.AppendCreateTable(entitySet);
                    builder.AppendSql(";");
                }

                foreach (AssociationSet associationSet in container.BaseEntitySets.OfType <AssociationSet>().OrderBy(s => s.Name))
                {
                    builder.AppendCreateForeignKeys(associationSet);
                    builder.AppendSql(";");
                }
            }
            return(builder.GetCommandText());
        }