public string GetCreateSql(TableMapping table) { var constraints = new List <string>(); if (this.PrimaryKey != null && table.PrimaryKey.Columns.Length == 1) { constraints.Add(string.Format(CultureInfo.InvariantCulture, "{0} PRIMARY KEY {1}", string.IsNullOrEmpty(this.PrimaryKey.Name) ? string.Empty : string.Format(CultureInfo.InvariantCulture, "CONSTRAINT {0}", this.PrimaryKey.Name), this.PrimaryKey.Direction)); if (table.OnPrimaryKeyConflict != ConflictResolution.Default) { constraints.Add(string.Format(CultureInfo.InvariantCulture, "ON CONFLICT {0}", table.OnPrimaryKeyConflict)); } if (table.AutoIncrementColumn == this) { constraints.Add("AUTOINCREMENT"); } } if (this.Unique != null) { constraints.Add(string.Format(CultureInfo.InvariantCulture, "UNIQUE {0}", this.Unique.OnConflict != ConflictResolution.Default ? string.Format(CultureInfo.InvariantCulture, "ON CONFLICT {0}", this.Unique.OnConflict) : string.Empty)); } if (!this.IsNullable) { constraints.Add("NOT NULL"); } if (this.Checks.Any()) { constraints.Add(string.Join(" ", this.Checks.Select(c => string.Format(CultureInfo.InvariantCulture, "CHECK ({0})", c)).ToArray())); } if (!string.IsNullOrEmpty(this.DefaultValue)) { constraints.Add(string.Format(CultureInfo.InvariantCulture, "DEFAULT({0})", this.DefaultValue)); } if (this.Collation != Collation.Default) { constraints.Add(string.Format(CultureInfo.InvariantCulture, "COLLATE {0}", this.Collation)); } return(string.Format(CultureInfo.InvariantCulture, "[{0}] {1} {2}", this.Name, OrmHelper.SqlType(this), string.Join(" ", constraints.ToArray()))); }