Exemple #1
0
        void IProviderExtend.CreateTable(MetaTable metaTable)
        {
            //var metaTable = services.Model.GetTable(metaTable);
            var command = MySqlBuilder.GetCreateTableCommand(metaTable);

            services.Context.ExecuteCommand(command);
        }
Exemple #2
0
        void IProviderExtend.CreateForeignKeys(MetaTable metaTable)
        {
            //  var metaTable = services.Model.GetTable(metaTable);
            var commands = MySqlBuilder.GetCreateForeignKeyCommands(metaTable);

            foreach (var command in commands)
            {
                services.Context.ExecuteCommand(command);
            }
        }
Exemple #3
0
        public void CreateDatabase()
        {
            if (DatabaseExists())
            {
                throw SqlClient.Error.CreateDatabaseFailedBecauseSqlCEDatabaseAlreadyExists(dbName);
            }

            //创建数据库文件
            var connection = new MySqlConnection(GetConnectionString(string.Empty));

            connection.Open();

            var transaction = connection.BeginTransaction();

            Execute(connection, transaction, MySqlBuilder.GetCreateDatabaseCommand(dbName, null, null));
            try
            {
                MetaModel model = services.Model;
                foreach (MetaTable table in model.GetTables())
                {
                    string createTableCommand = MySqlBuilder.GetCreateTableCommand(table);

                    if (!string.IsNullOrEmpty(createTableCommand))
                    {
                        Execute(connection, transaction, createTableCommand);
                    }
                }

                foreach (MetaTable table in model.GetTables())
                {
                    foreach (string commandText in MySqlBuilder.GetCreateForeignKeyCommands(table))
                    {
                        if (!string.IsNullOrEmpty(commandText))
                        {
                            Execute(connection, transaction, commandText);
                        }
                    }
                }

                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                connection.Close();
            }
        }
Exemple #4
0
        public void CreateTable(MetaTable metaTable)
        {
            string createTableCommand = MySqlBuilder.GetCreateTableCommand(metaTable);

            Execute(Connection, Transaction, createTableCommand);
        }