/// <summary> /// Initializes a new instance of the <see cref="DatabaseRelationalKey"/> class. /// </summary> /// <param name="childTableName">The child table name.</param> /// <param name="childKey">The child key.</param> /// <param name="parentTableName">The parent table name.</param> /// <param name="parentKey">The parent key.</param> /// <param name="deleteAction">The delete action.</param> /// <param name="updateAction">The update action.</param> /// <exception cref="ArgumentException"> /// <paramref name="updateAction"/> or <paramref name="deleteAction"/> will throw this exception if given an invalid enum value. /// Alternatively if the child key is not a foreign key this will also be thrown. /// Furthermore, if the parent key is not a unique or primary key, this will also be thrown. /// </exception> /// <exception cref="ArgumentNullException"><paramref name="parentTableName"/> or <paramref name="childTableName"/> or <paramref name="parentKey"/> or <paramref name="childKey"/> is <c>null</c></exception> public DatabaseRelationalKey(Identifier childTableName, IDatabaseKey childKey, Identifier parentTableName, IDatabaseKey parentKey, ReferentialAction deleteAction, ReferentialAction updateAction) { if (!deleteAction.IsValid()) { throw new ArgumentException($"The { nameof(ReferentialAction) } provided must be a valid enum.", nameof(deleteAction)); } if (!updateAction.IsValid()) { throw new ArgumentException($"The { nameof(ReferentialAction) } provided must be a valid enum.", nameof(updateAction)); } ChildTable = childTableName ?? throw new ArgumentNullException(nameof(childTableName)); ChildKey = childKey ?? throw new ArgumentNullException(nameof(childKey)); ParentTable = parentTableName ?? throw new ArgumentNullException(nameof(parentTableName)); ParentKey = parentKey ?? throw new ArgumentNullException(nameof(parentKey)); if (ChildKey.KeyType != DatabaseKeyType.Foreign) { throw new ArgumentException($"The child key must be a foreign key, instead given a key of type '{ childKey.KeyType }'.", nameof(childKey)); } if (ParentKey.KeyType != DatabaseKeyType.Primary && ParentKey.KeyType != DatabaseKeyType.Unique) { throw new ArgumentException($"The parent key must be a primary or unique key, instead given a key of type '{ parentKey.KeyType }'.", nameof(parentKey)); } DeleteAction = deleteAction; UpdateAction = updateAction; }
public OnDeleteActionAttribute(ReferentialAction action, params Type[] dialects) : base(dialects) { if (!action.IsValid()) { throw new ArgumentException($"The { nameof(ReferentialAction) } provided must be a valid enum.", nameof(action)); } Action = action; }
public OnDeleteActionAttribute(ReferentialAction action) : base(new[] { Dialect.All }) { if (!action.IsValid()) { throw new ArgumentException($"The { nameof(ReferentialAction) } provided must be a valid enum.", nameof(action)); } Action = action; }
public ForeignKey( string constraintName, IEnumerable <string> columnNames, Identifier parentTableName, string parentConstraintName, IEnumerable <string> parentColumnNames, ReferentialAction deleteAction, ReferentialAction updateAction, string rootPath ) : base(constraintName) { if (columnNames == null || columnNames.Empty()) { throw new ArgumentNullException(nameof(columnNames)); } if (parentTableName == null) { throw new ArgumentNullException(nameof(parentTableName)); } if (parentColumnNames == null || parentColumnNames.Empty()) { throw new ArgumentNullException(nameof(parentColumnNames)); } if (!deleteAction.IsValid()) { throw new ArgumentException($"The { nameof(ReferentialAction) } provided must be a valid enum.", nameof(deleteAction)); } if (!updateAction.IsValid()) { throw new ArgumentException($"The { nameof(ReferentialAction) } provided must be a valid enum.", nameof(updateAction)); } if (rootPath == null) { throw new ArgumentNullException(nameof(rootPath)); } ChildColumnNames = columnNames.Join(", "); ParentConstraintName = parentConstraintName; ParentTableName = parentTableName.ToVisibleName(); ParentTableUrl = rootPath + UrlRouter.GetTableUrl(parentTableName); ParentColumnNames = parentColumnNames.Join(", "); DeleteActionDescription = _actionDescription[deleteAction]; UpdateActionDescription = _actionDescription[updateAction]; }
public ReflectionRelationalKey(Identifier childTableName, IDatabaseKey childKey, Identifier parentTableName, IDatabaseKey parentKey, ReferentialAction deleteAction, ReferentialAction updateAction) { if (childTableName == null) { throw new ArgumentNullException(nameof(childTableName)); } if (childKey == null) { throw new ArgumentNullException(nameof(childKey)); } if (parentTableName == null) { throw new ArgumentNullException(nameof(parentTableName)); } if (parentKey == null) { throw new ArgumentNullException(nameof(parentKey)); } if (!deleteAction.IsValid()) { throw new ArgumentException($"The { nameof(ReferentialAction) } provided must be a valid enum.", nameof(deleteAction)); } if (!updateAction.IsValid()) { throw new ArgumentException($"The { nameof(ReferentialAction) } provided must be a valid enum.", nameof(updateAction)); } // perform validation var relationalKey = new DatabaseRelationalKey(childTableName, childKey, parentTableName, parentKey, deleteAction, updateAction); ChildTable = relationalKey.ChildTable; ChildKey = relationalKey.ChildKey; ParentTable = relationalKey.ParentTable; ParentKey = relationalKey.ParentKey; DeleteAction = relationalKey.DeleteAction; UpdateAction = relationalKey.UpdateAction; ValidateColumnSetsCompatible(ChildTable, ChildKey, ParentTable, ParentKey); }