Beispiel #1
0
        public void EnsureExists(SqlTable table)
        {
            var columns = GetColumns(table);

            if (columns.Count > 0)
            {
                if (!table.Columns.All(c => columns.Contains(c.Name)) || !columns.All(c => table.Columns.Any(c2 => c2.Name == c)))
                {
                    var from = new SqlTable(table.Name, columns.Select(s => new SqlColumn(s, MySqlDbType.String)).ToList());
                    database.Query(creator.AlterTable(from, table));
                }
            }
            else
            {
                database.Query(creator.CreateTable(table));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Ensures a table exists and matches the given structure.
        /// </summary>
        /// <param name="table">table to create</param>
        /// <returns>Returns true if the table was created</returns>
        public bool EnsureTableStructure(SqlTable table)
        {
            List <string> columns = GetColumns(table);

            if (columns.Count > 0)
            {
                if (!table.Columns.All(c => columns.Contains(c.Name)) || !columns.All(c => table.Columns.Any(c2 => c2.Name == c)))
                {
                    SqlTable from = new SqlTable(table.Name, columns.Select(s => new SqlColumn(s, MySqlDbType.String)).ToList());
                    database.Query(creator.AlterTable(from, table));
                }
            }
            else
            {
                database.Query(creator.CreateTable(table));
                return(true);
            }
            return(false);
        }