public TableConstraint( string identifier, DatabaseKeyType keyType, string constraintName, IEnumerable <string> columnNames, IEnumerable <string> columnTypes ) { if (identifier.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(identifier)); } Identifier = identifier; if (!keyType.IsValid()) { throw new ArgumentException($"The { nameof(DatabaseKeyType) } provided must be a valid enum.", nameof(keyType)); } KeyTitle = _keyTypeTitles[keyType]; KeyType = keyType; ConstraintName = constraintName ?? string.Empty; ColumnNames = columnNames?.ToList() ?? throw new ArgumentNullException(nameof(columnNames)); ColumnTypes = columnTypes?.ToList() ?? throw new ArgumentNullException(nameof(columnTypes)); }
protected Key(IEnumerable <IModelledColumn> columns, DatabaseKeyType keyType) { if (columns == null || columns.Empty() || columns.AnyNull()) { throw new ArgumentNullException(nameof(columns)); } if (!keyType.IsValid()) { throw new ArgumentException($"The { nameof(DatabaseKeyType) } provided must be a valid enum.", nameof(keyType)); } Columns = columns; KeyType = keyType; }
/// <summary> /// Initializes a new instance of the <see cref="SqliteDatabaseKey"/> class. /// </summary> /// <param name="name">The constraint name, if available.</param> /// <param name="keyType">Type of the key constraint.</param> /// <param name="columns">A collection of table columns.</param> /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="columns"/> is <c>null</c>. Alternatively, if <paramref name="columns"/> is empty or has <c>null</c> values.</exception> /// <exception cref="ArgumentException"><paramref name="keyType"/> is not a valid enum.</exception> public SqliteDatabaseKey(Option <Identifier> name, DatabaseKeyType keyType, IEnumerable <IDatabaseColumn> columns) { if (columns == null || columns.Empty() || columns.AnyNull()) { throw new ArgumentNullException(nameof(columns)); } if (!keyType.IsValid()) { throw new ArgumentException($"The { nameof(DatabaseKeyType) } provided must be a valid enum.", nameof(keyType)); } Name = name.Map(n => Identifier.CreateQualifiedIdentifier(n.LocalName)); KeyType = keyType; Columns = columns.ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="DatabaseKey"/> class. /// </summary> /// <param name="name">A constraint name, if available.</param> /// <param name="keyType">The key constraint type.</param> /// <param name="columns">The columns covered by the key.</param> /// <param name="isEnabled">Whether the constraint is enabled.</param> /// <exception cref="ArgumentNullException"><paramref name="columns"/> is <c>null</c> or contains <c>null</c> values.</exception> /// <exception cref="ArgumentException"><paramref name="keyType"/> is an invalid enum value.</exception> public DatabaseKey(Option <Identifier> name, DatabaseKeyType keyType, IReadOnlyCollection <IDatabaseColumn> columns, bool isEnabled) { if (columns == null || columns.Empty() || columns.AnyNull()) { throw new ArgumentNullException(nameof(columns)); } if (!keyType.IsValid()) { throw new ArgumentException($"The { nameof(DatabaseKeyType) } provided must be a valid enum.", nameof(keyType)); } Name = name.Map(n => Identifier.CreateQualifiedIdentifier(n.LocalName)); // strip to localname only KeyType = keyType; Columns = columns; IsEnabled = isEnabled; }
/// <summary> /// Initializes a new instance of the <see cref="PostgreSqlDatabaseKey"/> class. /// </summary> /// <param name="name">The key constraint name.</param> /// <param name="keyType">Type of the key constraint.</param> /// <param name="columns">A collection of table columns.</param> /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="columns"/> is <c>null</c>. Alternatively, if <paramref name="columns"/> is empty or has <c>null</c> values.</exception> /// <exception cref="ArgumentException"><paramref name="keyType"/> is not a valid enum.</exception> public PostgreSqlDatabaseKey(Identifier name, DatabaseKeyType keyType, IReadOnlyCollection <IDatabaseColumn> columns) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (columns == null || columns.Empty() || columns.AnyNull()) { throw new ArgumentNullException(nameof(columns)); } if (!keyType.IsValid()) { throw new ArgumentException($"The { nameof(DatabaseKeyType) } provided must be a valid enum.", nameof(keyType)); } Name = Option <Identifier> .Some(name.LocalName); KeyType = keyType; Columns = columns; }