SchemaNaming
The naming convention for database constraints and indexes, in one place so the DDL that creates them and the comparison that audits them can never drift apart.
メソッド
public static string ForeignKey(string tableName, string columnName)
result = SchemaNaming.ForeignKey(tableName, columnName)
Builds the foreign-key constraint name — FK_{Table}_{Column}. The name keys off the referencing column rather than the referenced table, so a table holding two foreign keys to the same parent still gets two distinct names.
- tableName
- Table that holds the foreign-key column.
- columnName
- The foreign-key column.
戻り値: The constraint name.
public static string Index(string tableName, IEnumerable<string> columnNames, bool unique)
result = SchemaNaming.Index(tableName, columnNames, unique)
Builds the index name — IX_{Table}_{Column…}, or UX_… when the index is unique. Columns appear in key order.
- tableName
- Table the index belongs to.
- columnNames
- Indexed columns, in key order.
- unique
- Whether the index enforces uniqueness.
戻り値: The index name.
public static string Index(string tableName, string columnName, bool unique)
result = SchemaNaming.Index(tableName, columnName, unique)
Builds the single-column index name — IX_{Table}_{Column}, or UX_… when the index is unique.
- tableName
- Table the index belongs to.
- columnName
- The indexed column.
- unique
- Whether the index enforces uniqueness.
戻り値: The index name.
public static bool IsDatabaseGenerated(string name)
result = SchemaNaming.IsDatabaseGenerated(name)
Determines whether is an identifier the database generated for itself rather than one our DDL supplied. Such names cannot be made to follow the convention, so the naming audit ignores them.
- name
- Constraint or index name as stored by the database.
戻り値: when the database owns the name.
public static string PrimaryKey(string tableName)
result = SchemaNaming.PrimaryKey(tableName)
Builds the primary-key constraint name for — PK_{Table}.
- tableName
- Table the primary key belongs to.
戻り値: The constraint name.
フィールド
public const string ForeignKeyPrefix
value = SchemaNaming.ForeignKeyPrefix
Prefix of a foreign-key constraint name.
public const string IndexPrefix
value = SchemaNaming.IndexPrefix
Prefix of a non-unique index name.
public const string PrimaryKeyPrefix
value = SchemaNaming.PrimaryKeyPrefix
Prefix of a primary-key constraint name.
public const string UniqueIndexPrefix
value = SchemaNaming.UniqueIndexPrefix
Prefix of a unique index name, so uniqueness is visible without inspecting the index.